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中正确设置并传递命令行参数给Java程序的main方法,适用于需要从外部接收输入参数的Java应用程序。通过右键点击目标类,选择运行配置,可以在程序参数栏中输入所需的参数。
902

被折叠的 条评论
为什么被折叠?



