首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

欧拉项目 首先题

2012-10-07 
欧拉项目 第一题最近在学spring技术,可是又迷恋上了欧拉项目,下面送上欧拉项目的一道小菜开开胃?If we lis

欧拉项目 第一题

最近在学spring技术,可是又迷恋上了欧拉项目,下面送上欧拉项目的一道小菜开开胃

?

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

?

?

翻译过来就是:找到1000以内所有能被3或者5整除的自然数,求他们的和。

?

public class Project1 {public static void main(String[] args) {int sum = 0;for (int i = 0; i < 1000; i++) {if (i % 3 == 0 || i % 5 == 0) {System.out.println(i);sum += i;}}System.out.println(sum);}}
?

?

热点排行