读书人

欧拉项目 首先题

发布时间: 2012-10-07 17:28:51 作者: rapoo

欧拉项目 第一题

最近在学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);}}
?

?

读书人网 >编程

热点推荐