其他分享
首页 > 其他分享> > 求1-1000所有奇数的和

求1-1000所有奇数的和

作者:互联网

package com.itemma;
/*
 在前一个程序的基础之上,计算1~1000所有奇数的和。
  运算符 += 就是专门完成追加的。,
*/
import java.util.Scanner;
public class Complex02 {
    public static void main(String[] args) {
        int sum = 0;
        for(int number = 1;number<=1000;number++){
            if(number %2 == 0){
                continue;
            }else{
                sum += number;

            }

        }
        System.out.println(sum);

    }

        }


C:\Software\Java\jdk-17\bin\java.exe "-javaagent:E:\IntelliJ IDEA Community Edition 2021.3\lib\idea_rt.jar=62429:E:\IntelliJ IDEA Community Edition 2021.3\bin" -Dfile.encoding=UTF-8 -classpath "E:\IntelliJ IDEA Community Edition 2021.3\IDEA Studying\out\production\IDEA Studying" com.itemma.Complex02
250000

Process finished with exit code 0

标签:2021.3,奇数,sum,所有,number,Community,IDEA,Edition,1000
来源: https://blog.csdn.net/weixin_62130805/article/details/121587317