Java中break只能跳出当前循环,要想跳出多重循环可以使label标签:
例:
public class StepoverMultiLoop
{
public static void main(String[]
args) {
int count
= 0;
ok:
for (int i
= 0; i < 100; i++){
for (int j
= 0; j < 100; j++){
if ((i
+ j) == 10){
System. out.println(++count);
break ok;
}
}
}
}
}
时间: 2024-10-13 19:43:02