如何捕获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
热门推荐
10 上级买车祝福语大全简短
11 团体年会祝福语简短霸气
12 對好友毕业祝福语简短
13 恭喜新郎父母简短祝福语
14 迟到的过年祝福语简短
15 妈妈生日祝福语简短温暖
16 新年送老师简短祝福语
17 祝福语简短创意闺蜜
18 送离职同事简短祝福语