JAVA program that describes exception handling mechanism

 JAVA program that describes exception handling mechanism


Source code :


/* 
Write a JAVA program that describes exception handling mechanism 
 */
import java.util.Scanner;

class Division {
  public static void main(String[] args) {
    int a, b, result;
    Scanner input = new Scanner(System.in);
    System.out.println("Input two integers");
    a = input.nextInt();
    b = input.nextInt();
   // try block
    try {
    result  = a / b;
    System.out.println("Result = " + result);
    }
   // catch block
    catch (ArithmeticException e) {
    System.out.println("Exception caught: Division by zero.");
    }
  } 


Post a Comment

0 Comments

Close Menu