Java1到100之间的奇数之和与偶数之和

public class HW_1 {
    public static void main(String[] args){
        int anOddNumber = 0;/*奇数何初始化*/
        int anEvenNumber = 0;/*偶数和初始化*/
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0){
                anEvenNumber += i;
            }else {
                anOddNumber +=i;
            }
        }
        System.out.println("1~100的偶数和为:"+anEvenNumber);
        System.out.println("1~100的奇数和为:"+anOddNumber);
    }
}

你可能感兴趣的:(Java编程题,java,开发语言,ide)