Write a program in Java to implement Exception
handling
Program:
class Sk24
{
public static void main(String args[ ])
{
int a=60,b;
for (int i=5;i>=0;i--)
{
try{
b=a/i;
System.out.println("Output:"+b);
}
catch(ArithmeticException e)
{
System.out.println("Divide By Zero");
}
}
}
}
Compile:
D:\>javac
Sk24.java
Run:
D:\>java Sk24
Output:
Output:12
Output:15
Output:20
Output:30
Output:60
Divide By Zero
0 Comments