Download as pdf
Download as pdf
You are on page 1of 3
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Discover. Learn. Empower. Experiment No. 3.3 Student Name: Subham Raj UID: 21BCS3680 Branch: CSE Section/Group: 612-4 Semester: 3° Date of Performance: 11/11/22 Subject Name: Object Oriented Programming Subject Code: 21CSH-218 Using Java Aim of the practical: Given two integers x and y as input, you have to computex/y. If x and y are not 32- bit signed integers or ify is zero, exception will occurand you have to report it. Objective: To study Exceptions and Exception Handling in Java . Program Code: import java.io.*5 import java.util. *; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System. in); try { try { int x = new Integer(sc.nextInt()); int y = new Integer(sc.nextInt()); System. out.printIn(""+(x/y))5 } catch (InputMismatchException e) { system, out. printIn("java.util.InputMismatchexception"); DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Discover. Learn. Empower. } catch(Exception e) ‘ system.out.printIn(e) 5 + Output : Sample Test case 1: G Sample Test case 0 Input (stain) G sample Test case 10 * & sample Test case 2 Your Output stlou G sample Test case 3 3 @ sample Test case 4 expected Output 3 Sample Test Case 2: put (stdin) 10 Hello Your Output (stdout) java-util.Inputii smatchException Expected Output java.util. Input smatcheException Download Download Download Downlead DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Discover. Learn. Empower. Sample Test case 3 : Input (stdin) Download 10 ° Your Output (stdout) java.lang.ArithmeticException: / by zero Expected Qutput Download java.lang.ArithmeticException: / by zero

You might also like