public class ForDemo02 {
public static void main(String[] args) {
//100内奇数和偶数的和
int oddSum=0;//奇数
int evenSum=0;//偶数
for (int i = 0; i <= 100; i++) {
if(i%2!=0){
oddSum=oddSum+i;
}else{
evenSum=evenSum+i;
}
}
System.out.println("奇数的和为:"+oddSum);
System.out.println("偶数的和为:"+evenSum);
}
}
java100内奇数和偶数的和
最新推荐文章于 2022-12-27 21:21:03 发布