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);
                        }   
     
     
    }
}

Compiler Message
Success
Input (stdin)Download
10
3
Expected OutputDownload
3

Comments

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions