public class DoWhile {
public static void main(String[] args) {
int b = 0;
int i = 1;
do {
if(i%2==0){
b+=i;
i++;
}else{
System.out.println("程序错误");
}
} while(i<=10);
System.out.println("b:"+b);
}
}
public class DoWhile {
public static void main(String[] args) {
int b = 0;
int i = 1;
do {
if(i%2==0){
b+=i;
i++;
}else{
System.out.println("程序错误");
}
} while(i<=10);
System.out.println("b:"+b);
}
}
死循环了呗。定义的变量也有多余用不上的,你是想求偶数之和吧。
public class DoWhile {
public static void main(String[] args) {
int b = 0;
int i=1;
do {
if(i%2==0){
b+=i;
}
i++;
} while(i<=10);
System.out.println("b:"+b);
}
}