用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 带入程序的运行之中

原文地址:https://www.cnblogs.com/Metamorphosis/p/4553175.html