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

解决方案 »

  1.   

    你应当在运行的时候输入参数,比如运行:
    java c03.RandomBounds lower
      

  2.   

    大哥能说清楚点吗
    我用的是eclipse,如何在运行的时候输入参数啊?
      

  3.   

    eclipse中输入参数好像不好输吧,我也想知道,
    我一般是再新建一个类来替换它.在这个类中设置要输入的参数,
    然后在main方法中调用它.
      

  4.   

    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方法里就可以接收到你输入的参灵数.
      

  5.   

    你在main函数里的String[] args 就能接收到以上设置的参数数据。
      

  6.   

    在dos下面运行class文件,用java c03.RandomBounds 【参数】
      

  7.   

    多谢  lky5387(风尘浪子) !