码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-08-29 13:08:30      阅读:139      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!