본문 바로가기

25년 1회차 정보처리기사 실기. Java try-catch 문제

by 귀엽소 2025. 4. 26.
반응형

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

 

유료강좌 꼭 듣기 

반응형

댓글