先来一段代码:

 1 package yichang;
 2 
 3 public class MyExceptionTest {
 4 
 5     public static void main(String[] args) {
 6         int dividend = 0;
 7         int divisor;
 8         int result = 0;
 9         try {
10             dividend = Integer.parseInt(args[0]);
11             divisor = Integer.parseInt(args[1]);
12             result = dividend / divisor;
13             System.out.println("redult=" + result);
14         } catch (ArrayIndexOutOfBoundsException e) {
15             System.out.println("输入参数量太少,请输入两个参数");
16 
17         } catch (NumberFormatException e) {
18             System.out.println("参数格式不对,请输入两个数字");
19         } catch (ArithmeticException e) {
20             System.out.println("除数为0");
21         }
22 
23     }
24 
25 }

想必新手对于

 dividend = Integer.parseInt(args[0]); divisor = Integer.parseInt(args[1]); 

会有一些困惑,这需要我们选中项目——运行方式——运行配置

dividend = Integer.parseInt(args[0])参数问题

dividend = Integer.parseInt(args[0])参数问题

设置程序自变量后点击应用——运行,即可

 

相关文章:

  • 2021-06-09
  • 2021-06-06
  • 2021-07-31
  • 2022-03-01
  • 2022-12-23
猜你喜欢
  • 2021-08-23
  • 2021-09-28
  • 2022-12-23
  • 2021-09-26
  • 2021-12-04
相关资源
相似解决方案