Java Exception Handling (Try-catch)

윤지현·2025년 4월 15일
0

HackerRank[Java]

목록 보기
40/57
  • 문제
  • 정답
import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            System.out.println(x / y);
        } catch (InputMismatchException e) {
            System.out.println("java.util.InputMismatchException");
        } catch (ArithmeticException e) {
            System.out.println("java.lang.ArithmeticException: " + e.getMessage());
        }
    }
}
  • 결과
profile
첫 시작

0개의 댓글