Published:
Updated:

https://www.hackerrank.com/challenges/java-exception-handling-try-catch/problem?isFullScreen=true


Solution

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(scanner.nextInt() / scanner.nextInt());
        } catch (ArithmeticException e) {
            System.out.println(e);
        } catch (InputMismatchException e) {
            System.out.println(e.getClass().getName());
        }
    }
}

Leave a comment