1 public class Main {
2
3 public static void main(String[] args) {
4 System.out.println("start");
5 flag: //标志位
6 for(int i=0;i<100;i++) {
7 for(int j=0;j<100;j++) {
8 for(int k=0;k<100;k++) {
9 if(i+j+k == 156) {
10 System.out.println("i="+i);
11 System.out.println("j="+j);
12 System.out.println("k="+k);
13 break flag;
14 }
15
16 }
17 }
18 }
19 System.out.println("end");
20 }
21 }
通过增加标志位退出多重循环。
来源:https://www.cnblogs.com/lick468/p/11391566.html