测试continue,本意是想跳过输出5,看不出来哪里错了,就是只能显示0,1,2,3,4
请大虾帮帮忙!
public class TestWhile {
public static void main(String args[]) {
int i = 0;
int step = 5;
while (i<10) {
if(i == step) {continue;}
System.out.println("i=" + i);
i++;
}
}
}
请大虾帮帮忙!
public class TestWhile {
public static void main(String args[]) {
int i = 0;
int step = 5;
while (i<10) {
if(i == step) {continue;}
System.out.println("i=" + i);
i++;
}
}
}
public class TestWhile {
public static void main(String args[]) {
int i = 0;
int step = 5;
while (i < 10) {
if (i == step) {
i++;
continue;
}
System.out.println("i=" + i);
i++;
}
}
}
如果要是修改的话,可将if(i == step) {continue;}改为if(i == step) {i++;continue;},这样就可以了
你的程序应该改为下面的样子
public class TestWhile {
public static void main(String args[]) {
int i = 0;
int step = 5;
while (i<10) {
if(i == step) { i++; continue;} //加上 i++; 是关键
System.out.println("i=" + i);
i++;}
} }
public class TestWhile {
public static void main(String args[]) {
int i = 0;
int step = 5;
while (i<10) {
if(i == step) //当i=5的时候执行此步
{
continue;//跳到while判断出!!!!却没有执行i++
//也就是说if条件永远执行 进入了死循环
//因此执行到i=4后就不能再继续执行了
}
System.out.println("i=" + i);
i++;
}
}
}你用的编译器是eclipse吗???
如果是的话,你可以看到编译器的红点是一直亮着的,也就意味着程序一直没有执行完毕
也就是说明了死循环!!!