for 循环的案例分析
for 循环的案例分析
//计算0到100以内基数和偶数的和
public static void main(String[] args) {
//计算0到100以内基数和偶数的和
int oddSum = 0;
int evenSum = 0;
for (int i = 0; i<= 100; i++) {
if(i%2==0){
evenSum+=i;
}else {
oddSum+=i;
}
}
System.out.println("基数的和:"+oddSum);
System.out.println("基数的和:"+evenSum);
////用for循环输出1···1000之间能被5整除的数,并且每行输出3个
for (int j = 0; j <= 1000; j++) {
if(j%5==0) {
System.out.print(j+"\t");
}
if (j%(5*3)==0) {
System.out.println();
}
}