eclipse & AS 带参数运行main()

阅读更多
public static void main(String[] args) {

    Double d1 = Double.valueOf(args[0]);
    Double d2 = Double.valueOf(args[1]);
    double result = d1.doubleValue() + d2.doubleValue();
    System.out.println(args[0] + "+" + args[1] + "=" + result);

}

 在main函数中运行需要命令行输入参数时,如果通过eclipse运行会报错

这需要设置eclipse的运行参数:

http://stackoverflow.com/questions/12222153/eclipse-how-we-take-arguments-for-main-when-run

 

Right click the class. Then go to Run as > Run configurations. Select the program on the left side. Then on the arguments tab you will see Program Arguments. Enter your program arguments in this textarea, if you would like to pass multiple arguments separate the arguments by spaces.

 

 

2.AS:

编译一次,报错后在Run标签下Edit Configuration...里面的Program argument可以设置

你可能感兴趣的:(eclipse,main,arguments)