需要输入参数的程序用Eclipse怎么运行

class NewRoot {
public static void main(String[] arguments) {
int number = 100;
String count = "25";
float sentence = 17.5F;
if(arguments.length > 0) {
number = Integer.parseInt(arguments[0]);
}
System.out.println("The square root of "
+ number
+ " is "
+Math.sqrt(number));
System.out.println(Math.sqrt(Integer.parseInt(count)));
System.out.println("My sentence has been reduced to "
+ sentence + " years.");
}
}
像这样的输入arguments[0],就可以改变输出值,在dos里可以输入java NewRoot 200实现,但是在Eclipse要怎么办才可以呢?
有人说在console里输入,但是我试了一下,console是只读的,不能打字。。。

操作步骤

第一步:在要运行的程序页面右键->run as->run configuration

第二步:Arguments->program arguments->填写参数->点击run即可

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-01
想在控制台输入得写这句:
Scanner s = new Scanner(System.in);
第2个回答  2011-12-01
右击你的代码 ---->【Run as】---->【Run configurations】--->【Java Application】--->【arguments】:然后在Program arguments里输入参数即可本回答被提问者采纳