class Test {
public static void main(String[] args) {
int a, b, i = 0;
try {
a = Integer.parseInt(args[i]);
i++;
b = Integer.parseInt(args[i]);
System.out.println("商为:" + a / b);
System.out.println("余数为:" + a % b);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("缺少第" + (i + 1) + "个参数!");
} catch (NumberFormatException e) {
System.out.println("第" + (i + 1) + "个参数格式错误!");
} catch (ArithmeticException e) {
System.out.println("除数不能为0!");
}
}
}
求两个数的商和余数 抛出异常
最新推荐文章于 2023-08-01 21:28:34 发布