hacker rank 47th java solution(java exception(try-catch))
48. JAVA EXCEPTION HANDLING (TRY-CATCH)
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
try{
Scanner sn = new Scanner(System.in);
int x=sn.nextInt();
int y = sn.nextInt();
int k=x/y;
System.out.println(k);
}catch(InputMismatchException e){
System.out.println(e.getClass().getName());
}catch(ArithmeticException e){
System.out.println(e);
}
}
}
Comments