In this HackerRank Java Exception Handling (Try-catch) problem you will be given two integers x and y as input, you have to compute x/y. If x and y are not 32 bit signed integers or if y is zero, an exception will occur and you have to report it. Read sample Input/Output to know what to report in case of exceptions.

HackerRank Java Exception Handling (Try-catch) problem solution

HackerRank Java Exception Handling (Try-catch) problem solution

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int x = sc.nextInt();
            int y = sc.nextInt();
            System.out.println(x/y);
        } catch(java.util.InputMismatchException e) {
            System.out.println("java.util.InputMismatchException");
        } catch(Exception e) {
            System.out.println(e);
        }
        
    }
}