자바의 정석 unreachable statement
조회수 1677회
자바의 정석에서 나온 코드 그대로 작성하여 해봤는데
public class SampleNameFor {
public static void main(String[] args) {
Loop1:for (int i = 2; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (j == 5)
break Loop1;
break; ⟵ 여기서나
continue Loop1; ⟵ 여기서 unreachable statement 이런 오류들이 뜨는데 해결법 좀 알려주세요..
continue;
System.out.println(i + "*" + j + "=" + i * j);
}
System.out.println();
}
}
}
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
2 답변
-
조건 4개중에 1개 택하는 예제 아닐까요?
public class SampleNameFor { public static void main(String[] args) { Loop1:for (int i = 2; i <= 9; i++) { for (int j = 1; j <= 9; j++) { if (j == 5) break Loop1; // if(j==5) 조건 4개 중 1개 택 System.out.println(i + "*" + j + "=" + i * j); } System.out.println(); } } }
-
(•́ ✖ •̀)
알 수 없는 사용자
-
-
break Loop1;
라인 아래로 실행할 수 있는 조건이 있는지 따져보세요.단순 논리 문제에요.
변수 j 가 5가되면 Loop1 이 끝납니다.
질문의 화살표 라인은 오류 메세지 그대로 "도달할 수 없는 문장"입니다.
댓글 입력