Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.InputMismatchException;
- class Exceptions{
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter two numbers to perform division:-");
- try{
- int a = sc.nextInt();
- int b = sc.nextInt();
- System.out.println("The division is "+a/b);
- }catch(InputMismatchException e){
- System.out.println("The input should be an int.");
- }catch(ArithmeticException e){
- System.out.println("The second number must not be 0.");
- }catch(Exception e){
- System.out.println("Some error has occured.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement