欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

eclipse & AS 带参数运行main()

程序员文章站 2022-07-04 16:55:59
...
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://*.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.

eclipse & AS 带参数运行main()
            
    
    博客分类: eclipseandroid studio eclipsemain arguments 

 

 

2.AS:

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