A/B 控制台输入语句-异常

来源:互联网 发布:传奇霸业转生修为数据 编辑:程序博客网 时间:2024/06/14 13:51
try
{
// Scanner s = new Scanner(System.in);
// Integer a = s.nextInt();
// Integer b = s.nextInt();
// int c = a/b;
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = a/b;
System.out.print("相除结果是:" + c);

}
catch(IndexOutOfBoundsException ie)
{
System.out.print("数组越界");
}
catch(NumberFormatException ne)
{
System.out.print("数字格式异常");
}
catch(ArithmeticException ae)
{
System.out.print("算术异常");
}
catch(Exception e)
{
System.out.print("未知异常");

}


控制台输入

右键-〉Run as-〉Run configurations-〉
(1)选择要进行控制台输入的Main函数
(2)“(x)=Arguments”标签,输入main函数参数,点击运行即可。


0 0