1到100偶数和奇数和,用for加if

package structure;


import java.util.Scanner;

public class Domofor {
public static void main(String[] args) {
int sum = 0;
int sum1 = 0;
for (int i = 0; i <= 100; i++) {
if (i % 2 == 0) {
sum = sum + i;


}

}
System.out.println(sum);
System.out.println("********************************");
for (int j = 1; j <= 100; j++) {
if(j%2==1)
sum1 = sum1+j;
}
System.out.println(sum1);
System.out.println("奇数和偶数和是" + (sum + sum1));


}


}

1到100偶数和奇数和,用for加if

上一篇:TeamCity : 配置 Build 过程


下一篇:177. 第N高的薪水