// Guess the print out, then run it.
// A good IQ test
public class A {
public static void main(String args[]) {
int x = 0;
while (x < 10) {
System.out.print(" " + x);
switch (x) {
case 5: x += 2;
continue;
case 2: break;
case 7: break;
default: x++;
};
x++;
}
}
}
The answer is:^-^
Can we put a continue in a switch-case statement?
本文通过一个Java程序实例,展示了如何使用while循环和switch语句来控制程序流程。该程序打印出0到9之间的整数,并在特定条件下改变计数方式。

被折叠的 条评论
为什么被折叠?



