Network disconnected
Description
ExceptionExam
클래스의 get50thItem
메소드에서는 매개변수로 받은 array의 50번째 값을 return합니다. 만약 array의 크기가 50보다 작을 경우에는 ArrayIndexOutOfBoundsException이라는 예외가 발생하는데요. get50thItem
이 ArrayIndexOutOfBoundsException를 throw
하도록 정의해 보세요.
throws
는 예외가 발생했을 때, 예외를 호출한 쪽에서 처리하도록 던져줍니다.
예를 들어, 아래의 코드에서는 메소드 선언 뒤에 throws ArithmeticException
이 적혀있는 것을 알 수 있습니다. 이렇게 적어놓으면 divide메소드는 ArithmeticException이 발생하니 divide메소드를 호출하는 쪽에서 오류를 처리하라는 뜻입니다.
public static void main(String[] args) {
int i = 10;
int j = 0;
try{
int k = divide(i, j);
System.out.println(k);
} catch(ArithmeticException e){
System.out.println("0으로 나눌수 없습니다.");
}
}
public static int divide(int i, int j) throws ArithmeticException{
int k = i / j;
return k;
}
Result
Stop
Result of [Run Test] or [Submit] will be displayed here
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.