帮忙看下这段JAVA代码错在哪里!!

2024-12-31 03:33:31
推荐回答(3个)
回答1:

for(i%2!=0){
oddSum += i;
}else{
evenSum += i;
}
for改成if,试试

回答2:

public static void main(String[] args) {
int oddSum = 0;
int evenSum = 0;
for (int i = 0; i <= 100; i++) {
if (i % 2 != 0) {
oddSum += i;
} else {
evenSum += i;
}
}
System.out.println(oddSum);
System.out.println(evenSum);
}

for(i%2!=0){ 改为 if(i%2!=0)

回答3:

第二个for改成if