public class HomeworkException01 {
public static void main(String[] args) {
try {
if (args.length != 2){
throw new ArrayIndexOutOfBoundsException("参数个数错误");
}
int n1 = Integer.parseInt(args[0]);
int n2 = Integer.parseInt(args[1]);
double res = cal(n1,n2);
System.out.println("n1/n2= " + res);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
} catch (NumberFormatException e){
System.out.println("参数格式错误,请输入整数");
}catch (ArithmeticException e){
System.out.println("除数不能为0");
}
}
public static double cal(int n1,int n2){
return n1/n2;
}
}