Write a program to implement the concept of Exception Handling using predefined exception.
Program Code:
import java.lang.*;
class Exception_handle
{
public static void main(String argv[])
{
int a=10,b=5,c=5,x,y;
try
{
x=a/(b-c);
}
catch(ArithmeticException e)
{
System.out.println("DIVISION BY ZERO");
}
y=a/(b+c);
System.out.println("y="+y);
}
}
Output:
DIVISION BY ZERO
y=1
Post A Comment:
0 comments: