JAVA Program to Handle the Division by Zero Exception

JAVA Program to Handle the Division by Zero Exception:

import java.io.*;
import java.util.*;
class divide_zero
{
 public static void main(String args[])
 {
   int a,b;
   Scanner in = new Scanner(System.in);
   System.out.println("Enter Number");
   a=Integer.parseInt(in.nextLine());

   try
   {
    b=a/0;
   }
   catch(ArithmeticException e)
   {
    System.out.println("Division by zero");
   }
 }
}
Enter Number
10
Division by zero

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.