eclipse & AS 带参数运行main()

Posted james_karon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 & AS 带参数运行main()的主要内容,如果未能解决你的问题,请参考以下文章

eclipse里面没有,或者有错误的主函数就不能run as java application

Java--Eclipse里运行程序,run--run as后没有java application解决办法

带参数的main函数,应该怎样运行呢

cmd运行jar带main参数

我是Eclipse的新手,我右键工程,发现里面的Run AS没有Run configurations这个选项,怎么解决?谢谢

eclipse中的web project项目运行 Run As → 1 run on server 出现图上的情况