求两个数的商和余数 抛出异常

来源:互联网 发布:淘宝买家退货发空包裹 编辑:程序博客网 时间:2024/05/22 15:56
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!");  } }}

0 0