1
7.5kviews
Write a program to perform division of two numbers accepted from user. Handle the I0Exception, NumberFormatException and ArithrieticException using multiple try catch block.

Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology

Marks: 10M

Year: May 2016

1 Answer
1
324views
Import java.util.Scanner; 
class MultiCatch 
{
public static void main(String arias()) 
int x,z;
 Scanner in = new Scanner(System.in); 
System.out.print("Enter number : "); 
x = in.nextInt();
 try 
{
z = 50 / x;     //statementl 
System.out.println("Division: "+z); 
 System.out.println("Try end..."); 
} 
catch(ArithmeticException e) 
{  
  System.out.println("Division by zero error."); 
  }  
 catch(IOException e)   {    
System.out.println("your are trying to divide number greater than 50 whch throw exception.");   }  
 catch(NumberFormatException  e)   {    
System.out.println("Invalid number.");   }  

 System.out.println("Program end..."); }
//end of main() 
}//end of class

output:

Enter number : 0

Division by zero error.

Enter number : -4

Invalid number.

Enter number : 160

your are trying to divide number greater than 50 whch throw exception.

exception IOException is never thrown in body of corresponding try statement catch(IOException e) {
^ 1 error

//I GOT THIS ERROR. I have written the same program


Please log in to add an answer.