Java Program To Implement Divide By Zero Exception

Java won't throw an exception in the event that you partition by float zero. It will identify a run-time error just on the off chance that you separate by integer zero, not double zero. On the off chance that you separate by 0.0, the outcome will be INFINITY

Java Program To Implement Divide By Zero Exception

import java.util.Scanner;
class DivideZero
{
static public void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter 2 numbers : ");
int a = sc.nextInt();
int b = sc.nextInt();
try
{
System.out.println("Quotient : " + (a/b));
}
catch(ArithmeticException e)
{
System.out.println(e);
}
}
}
Output:
Enter 2 numbers :
10
0
java.lang.ArithmeticException: / by zero


tags : divde by zero , java , java programs , java tutorial , tutorialspoint , java tutorialspoint , java code , exception handling , c++ , programs of c++ , programs of c , code camp

Post a Comment

Previous Post Next Post