Sunday 15 June 2014

Program to show Exception handling ( try and catch statement)

package sum;

import javax.swing.JOptionPane;

public class finallyaftercatch {

public static void main(String[] args) {
int a,b,c=0;
try
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));
c=a/b;
}
catch (NumberFormatException p)
{
System.out.print("wrong value entered");
}
catch (ArithmeticException p)
{
System.out.print("denominator zero entered");
}
finally {
System.out.print("\ndivision="+c); }

}

}
 enter A 5
enter B 0
denominator zero entered
division=0

No comments:

Post a Comment

SAY HELLO!!