首页 > 其他 > 详细

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

时间:2016-08-29 13:05:39      阅读:366      评论:0      收藏:0      [点我收藏+]

先来一段代码:

 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])参数问题

原文:http://www.cnblogs.com/liuyaozhi/p/5817557.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!