Write a java program to know above exception details using printStackTrace() Method

Write a java program to know above exception details using printStackTrace() Method

Program
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        int x,y,z;
        System.out.println("Enter x,y values :");
        Scanner s=new Scanner (System.in);
        try
        {
            x=s.nextInt();
            y=s.nextInt();
            z=x/y;
            System.out.println("Division of two number is : "+z);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Output:

Enter x,y values :10 0
java.lang.ArithmeticException
/ by zero
at Demp3.main(Demp3.java:13)


Exception Handling In Java



More Questions


166 . Write a java program to know above exception details using printStackTrace() Method
167 . Write a java program to know above exception details using getMessage Method
168 . Write a Throws Keyword Program
169 . Write a Finally block Program
170 . Write a program to handle negative age exception
171 . Write a program to handle negative salary exception
172 . Write a Simple interest program to handle negative amount and duration and interest using user defined exception
173 . Write a String length program
174 . Write a string charAt() method program
175 . Write a string toLowerCase() Program
176 . Write a String toUpperCase() program