1、编写应用程序,从命令行传入两个整型数作为除数和被除数。要求程序中捕获NumberFormatException 异常和ArithmeticException 异常,而且无论在哪种情况下,“总是被执行”这句话都会在控制台输出。
public static void main(String[] args) {
try{
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = a/b;
System.out.println(c);
}catch(NumberFormatException e){
System.out.println("输入不能转换为数字");
}catch (ArithmeticException e) {
System.out.println("算术异常");
}finally{
System.out.println("总是被执行");
}
}