package c03;//: c03:RandomBounds.java
// Does Math.random() produce 0.0 and 1.0?
// {RunByHand}
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.public class RandomBounds {
static void usage() {
System.out.println("Usage: \n\t" +
"RandomBounds lower\n\tRandomBounds upper");
System.exit(1);
}
public static void main(String[] args) {
if(args.length != 1) usage();
if(args[0].equals("lower")) {
while(Math.random() != 0.0)
; // Keep trying
System.out.println("Produced 0.0!");
}
else if(args[0].equals("upper")) {
while(Math.random() != 1.0)
; // Keep trying
System.out.println("Produced 1.0!");
}
else
usage();
}
}
运行这个程序,为什么没有提示我输入什么东西呢?
// Does Math.random() produce 0.0 and 1.0?
// {RunByHand}
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.public class RandomBounds {
static void usage() {
System.out.println("Usage: \n\t" +
"RandomBounds lower\n\tRandomBounds upper");
System.exit(1);
}
public static void main(String[] args) {
if(args.length != 1) usage();
if(args[0].equals("lower")) {
while(Math.random() != 0.0)
; // Keep trying
System.out.println("Produced 0.0!");
}
else if(args[0].equals("upper")) {
while(Math.random() != 1.0)
; // Keep trying
System.out.println("Produced 1.0!");
}
else
usage();
}
}
运行这个程序,为什么没有提示我输入什么东西呢?
java c03.RandomBounds lower
我用的是eclipse,如何在运行的时候输入参数啊?
我一般是再新建一个类来替换它.在这个类中设置要输入的参数,
然后在main方法中调用它.
1.点菜单里的Run
2.点击菜单里的[Run...]
3.弹出一个画面:Create,Manage,and run configuration
4.双击Java Application
5.在Mian class 那里找到你的Mian class
6.点击(x)=Argument选项卡,在Parogram argumerts:处输入你的参数就可以了.
7.点击Run button就可以了.
最后你在main方法里就可以接收到你输入的参灵数.