Java面试题总结之如何跳出多重循环

时间:2015-05-15 09:04:21   收藏:0   阅读:146
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;
                }
            }
         }
    }
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!