You are on page 1of 2

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 3.3

Student Name:Darshit Sheth UID: 21BCS7782


Branch: BE-CSE Section/Group: 817-A
Semester: 3rd Date of Performance:
Subject Name: OOPS JAVA

Aim:
Hacker rank problem related to Exception handling.

Objective:
You will be given two integers x and y as input, you have to compute .If and are
not bit signed integers or if is zero, exception will occur and you have to report it.
Read sample Input/Output to know what to report in case of exceptions.

Program Code:

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

public class Solution {

public static void main(String[] args)


{ Scanner scan = new Scanner(System.in);
try {
int x = scan.nextInt();
int y = scan.nextInt();
System.out.println(x / y);
} catch (ArithmeticException | InputMismatchException e)
{ if (e instanceof ArithmeticException) {
System.out.println("java.lang.ArithmeticException: / by zero");
} else if (e instanceof InputMismatchException)
{ System.out.println("java.util.InputMismatchException");
}
}
scan.close();
}
}

Name:-Darshit Sheth UID:-21BCS7782


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

OUTPUT:

Name:-Darshit Sheth UID:-21BCS7782

You might also like