• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Oraice
博客园    首页    新随笔    联系   管理    订阅  订阅

Multiples of 3 and 5

from https://projecteuler.net/problem=1
Problem 1:
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.

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

posted on 2016-03-29 15:27  ncp6  阅读(121)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3