将数字除以零时,将引发算术异常数字。
public class DividedByZero {
public static void main(String args[]) {
int a, b;
try {
a = 0;
b = 54/a;
System.out.println("hello");
} catch (ArithmeticException e) {
System.out.println("you cannot divide a number with zero");
}
}
}输出结果
you cannot divide a number with zero