需求
0-100之间的奇数和偶数的和
代码实现
package com.jichu.struct;
public class ForDemo01 {
public static void main(String[] args) {
//0-100之间的奇数和偶数的和
int odd = 0;
int even = 0;
for(int i=0;i<=100;i++){
if(i%2==0) {
even += i;
}else {
odd += i;
}
}
System.out.println("0-100的偶数和为"+even+",奇数和为:"+odd);
}
}
思路
奇数odd 偶数even