zoukankan      html  css  js  c++  java
  • 用Eclipse输入主参数参数值得方法

     如下面的程序:需要输入主参数的参数值去运行程序

    public class ExceptionDemo {

     /**   * @param args   */

     public static void main(String[] args) {  

     // TODO Auto-generated method stub      

          System.out.println("********计算开始********");

           int i = 0;

           int j = 0;

           try{

            String str1 = args[0];

            String str2 = args[1];

            i = Integer.parseInt(str1);

            j = Integer.parseInt(str2);

            int temp = i/j;  

           System.out.println("两个数相除的结果是:" + temp);

            System.out.println("-----------");

           }catch(ArithmeticException e){

            System.out.println("算术异常:"+e);

           }catch(NumberFormatException e){

            System.out.println("数据转换异常:"+e);

           }catch(ArrayIndexOutOfBoundsException e){

            System.out.println("数组越界异常:"+e);

           }

           System.out.println("********计算结束********");  }

    }

    1、选择程序,右键选择Run As--->Run Configuration页面,

    2、选择第二个页面(X)=Arguments,在Program arguments页面输入参数值,如10 2;中间用空格隔开;

    3、则程序运行的时候就会将args[0]=10,args[1]=2 带入程序的运行之中

  • 相关阅读:
    缓动动画的原理
    高级各行高亮显示
    返回顶部的小火箭
    事件委托
    原型链和原型的继承
    对象的构建和构造函数
    call、apply和bind
    闭包
    九宫格封装好的组件 样式可以自由改哦
    嘿嘿嘿嘿 马上就有新任务了 提前封装一个转盘抽奖组件
  • 原文地址:https://www.cnblogs.com/Metamorphosis/p/4553175.html
Copyright © 2011-2022 走看看