public class 奇数偶数求和 {
public static void main(String[] args) {
int i = 0;
int result1 = 0;
int result2 = 0;
while(i<=100) {
if(i%2==0) {
result1 = result1 + i;
}
else {
result2 = result2 + i;
}
i++;
}
System.out.println("100以内偶数和为"+result1);
System.out.println("100以内奇数和为"+result2);
}
}
image.png
网友评论