Arithmetic exception using try-catch block in java

Write a program to handle the Arithmetic exception using try-catch block in java.

package Exception_demo;
import java.util.*;
public class arithmetic_soln 
{
        public static void main(String args[])
    {
        int a,b,c=0;
        Scanner s=new Scanner(System.in);
        System.out.println("enter the value of a:");
        a=s.nextInt();
        System.out.println("enter the value of b:");
        b=s.nextInt();
        try
        {
            c=a/b;
            System.out.println("value of c is:"+c);
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
        
        System.out.println("bhavesh jain");
        
    }

}

Leave a Reply

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