1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class Test { public static void main(String[] args) { System.out.println("\n----中断单层循环的例子----"); String[] array = new String[] {"白露","丹顶鹤","黄鹂","鹦鹉","乌鸦","喜鹊","老鹰","布谷鸟","老鹰","灰文鸟","老鹰","百灵鸟"}; for (String string : array) { if (string.equalsIgnoreCase("老鹰")) break; System.out.print("有:" + string + " "); } System.out.println("\n\n----中单2层循环的例子----"); int[][] myScores = new int[][] {{67,78,63,22,66}, {55,68,78,95,44},{95,97,92,93,81}}; System.out.println("宝宝这次考试成绩:\n数学\t语文\t英语\t美术\t历史"); No1: for (int[] is : myScores) { for (int i : is) { System.out.print(i + "\t"); if(i<60) { System.out.println("\n等等," + i + "分的是什么?这个为什么不及格?"); break No1; } } System.out.println(); } } }
|