package com.java.myapp;
public class MyClass {
public static void main(String[] args) {
int x = 200 ;
int y = 0 ;
int z = x / y;
System.out.println(" x / y = " + z) ;
}
}
Output
Exception in thread "main" java.lang.ArithmeticException: / by zero
at com.java.myapp.MyClass.main(MyClass.java:9)
package com.java.myapp;
public class MyClass {
public static void main(String[] args) {
try {
int x = 200 ;
int y = 0 ;
int z = x / y;
System.out.println(" x / y = " + z) ;
} catch(ArithmeticException e) {
System.out.println("Number Incorrect.");
} catch(Exception e) {
System.out.println("Error Others.");
}
}
}