We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Java
  3. Exception Handling
  4. Java Exception Handling (Try-catch)
  5. Discussions

Java Exception Handling (Try-catch)

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • bisenpriyanshus1
    4 months ago+ 0 comments

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

    public class Solution {

    public static void main(String[] args) {
            Scanner scan= new Scanner (System.in);
            try {
                   int a=scan.nextInt();
        int b=scan.nextInt();
        int c=a/b;
        System.out.println(c);
        }catch(InputMismatchException ie){
            System.out.println("java.util.InputMismatchException");
        }catch(ArithmeticException ae){
            System.out.println("java.lang.ArithmeticException: / by zero");
        }
    
    }
    

    }

    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy