반응형
Java
try-catch-finally 문제
public class DivisionDemo{
public static void main(Strin[] args){
try{
int a = 5, b =0;
System.out.print(a/b); try 안에는 오류 발생 예상되는 코드 넣음. a/b=5/0 0으로 나누면 뭐든 0나오는 오류 발생.
} catch (ArithmeticException e) { 0으로 나누는 오류는 ArithmeticException에 해당함.
System.out.print("출력1");
} catch (NullPointerExcepion e) {
System.out.print("출력2");
} catch (ArrayIndexOutOfBoundsExcepion e) {
System.out.print("출력3");
} catch (Excepion e) {
System.out.print("출력4");
}finally { finally는 무조건 출력해줌.
System.out.print("출력5");
}
}
}
정답: 출력1출력2 |
https://youtu.be/JzeDc6p3wW4?si=-7WfoHYVmmyBlrX0
유료강좌 꼭 듣기
반응형
'정보처리기사 필답 실기' 카테고리의 다른 글
C언어, Java, 파이썬 코멘트 주석 처리 (0) | 2025.04.27 |
---|---|
2025년 1회 정보처리기사 실기. Java 오버로딩 문제 (0) | 2025.04.26 |
2025년 1회 정보처리기사 실기. Java Math.max(), 재귀함수 문제 (0) | 2025.04.26 |
2025년 1회 정보처리기사 실기. Java static 메서드 문제 (0) | 2025.04.26 |
25년 1회차 정보처리기사 실기. C언어 아스키코드 문제 (0) | 2025.04.26 |
댓글