Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views1 page

Exception

The document shows Java code that takes input from the user, divides two numbers, and catches any ArithmeticException errors that may occur from dividing by zero.

Uploaded by

Sameer khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Exception

The document shows Java code that takes input from the user, divides two numbers, and catches any ArithmeticException errors that may occur from dividing by zero.

Uploaded by

Sameer khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;
class Exception
{
public static void main(String arg[])
{
try
{
// declare and initialize here.
int a,b,c;
Scanner KB=new Scanner(System.in);
// input numbers here.
System.out.print("Enter first number : ");
a=KB.nextInt();

System.out.print("Enter second number : ");


b=KB.nextInt();

//throw to catch
c=a/b;
System.out.println("Result:"+c);
}
catch(ArithmeticException e)
{
System.out.println("Error:"+e.getMessage());
System.out.println("Error:"+e);
}
// here program ends.
System.out.println("End of Program...");
}
}

You might also like