如何捕获Java中的零除异常?
将数字除以零时,将引发算术异常数字。
示例
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
热门推荐
8 火把节祝福语简短
10 升职加薪的祝福语简短
11 朝鲜元旦祝福语大全简短
12 端午送老师祝福语简短
13 幼师离别祝福语老师简短
14 古风祝福语 唯美简短结婚
15 简短元旦祝福语古言
16 新年祝福语简短俏皮文案
17 社团迎新祝福语简短英语
18 国庆中秋祝福语大全简短