Exception handling using try and catch blocks(Arithmetic Exception
package Exceptions;
/**
*
* @author Mukesh Jha
*/
import java.io.*;
import java.lang.*;
class excep_prog
{
public static void main(String[] args) throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
int a,b,c;
double x=0,y;
System.out.println("enter value of a"); a=Integer.parseInt(dis.readLine());
System.out.println("enter value of b"); b=Integer.parseInt(dis.readLine());
System.out.println("enter value of c"); c=Integer.parseInt(dis.readLine());
try {
System.out.println("x value is"+x);
}
catch(ArithmeticException e) {
System.out.println("division by zero"); }
y=a/(b+c);
System.out.println("y value is"+y);
}
}
Program output
enter value of a
7
enter value of b
6
enter value of c
8
x value is0.0
y value is0.0
Exception handling using try and catch blocks(Arithmetic Exception
Reviewed by Mukesh Jha
on
12:47 AM
Rating:
No comments:
Add your comment