WAP that accepts two strings in integer format as in command line argument. The first number is divided by the second number and the result is displayed. There are catch blocks and to handle different types of exception. If division by zero is attempted, ArithmeticException occurs. Implement this program using try, catch and finally.

 

class ExceptionDemo
{
    public static void main(String args[])
    {
            int num=0;
            String c=args[0],d=args[1];
            if(c==null && d==null)
            {
                 System.out.println("null value");
            }   
            else
            {
                try
                {
                    int x = Integer.parseInt(c);
                    int y = Integer.parseInt(d);
           
                    num=x/y;
                    System.out.println("Number is--->"+num);
                }
                catch(ArithmeticException ae)
                {
                    System.out.println("Try Again"+ae);
                }
            }
    }
}

0 comments:

Post a Comment

Digital Marketing

Subscribe to RSS Feed Follow me on Twitter!