/*
Java break statement with label example.
This example shows how to use java break statement to terminate the labeled loop.
The following example uses break to terminate the labeled loop while searching two
dimensional int array.
*/
import java.io.*;
public class JavaBreakWithLabelExample {
public static void main(String[] args) {
int[][] intArray = new int[][]{{1,2,3,4,5},{10,20,30,40,50}};
boolean blnFound = false;
System.out.println("Searching 30 in two dimensional int array..");
Outer:
for(int intOuter=0; intOuter < intArray.length ; intOuter++) {
Inner:
for(int intInner=0; intInner < intArray[intOuter].length; intInner++) {
if(intArray[intOuter][intInner] == 30) {
blnFound = true;
break Outer;
}
}
}
if(blnFound == true)
System.out.println("30 found in the array");
else
System.out.println("30 not found in the array");
}
}
/*
Output would be
Searching 30 in two dimensional int array..
30 found in the array
*/
'자바·파이썬·자바스크립트 > Java 프로그래밍' 카테고리의 다른 글
cmd창 사용하기 (0) | 2012.03.12 |
---|---|
자바 삭제법 (0) | 2012.02.19 |
초보자 문제 (0) | 2011.12.16 |
자바 continue with label 예제 (0) | 2011.12.11 |
자바 continue 예제 (0) | 2011.12.11 |