日期:2014-05-20  浏览次数:20643 次

如何在命令行输入命令
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();
    }
}
运行这个程序,为什么没有提示我输入什么东西呢?

------解决方案--------------------
你应当在运行的时候输入参数,比如运行:
java c03.RandomBounds lower
------解决方案--------------------
eclipse中输入参数是一件很简单的事情,步骤如下:
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方法里就可以接收到你输入的参灵数.