Java- Arithmetic Exception Example

// Example of Arithmetic Exception

import java.util.*;


class Test
{

public static void main(String ar[])
{

int a,b,c;
a=12;
Scanner scan=new Scanner(System.in);

System.out.println("Enter value of denominator");
b=scan.nextInt();
c=a/b  ;    //  if b is 0 than divide by Zero exception fires.
System.out.println("after divide result= "+c);

}


}

//output

C:\JAVA>java Test
Enter value of denominator
0
Exception in thread "main" java.lang.ArithmeticException: / by zero
    at Test.main(Test.java:16)

Reactions: