如何在命令行输入命令

polaris_chow 2007-08-24 09:16:13
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();
}
}
运行这个程序,为什么没有提示我输入什么东西呢?
...全文
557 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuhaozhiyuan 2007-08-31
  • 打赏
  • 举报
回复
多谢 lky5387(风尘浪子) !
qiuqiupeng 2007-08-27
  • 打赏
  • 举报
回复
在dos下面运行class文件,用java c03.RandomBounds 【参数】
wuhaozhiyuan 2007-08-24
  • 打赏
  • 举报
回复
eclipse中输入参数好像不好输吧,我也想知道,
我一般是再新建一个类来替换它.在这个类中设置要输入的参数,
然后在main方法中调用它.
polaris_chow 2007-08-24
  • 打赏
  • 举报
回复
大哥能说清楚点吗
我用的是eclipse,如何在运行的时候输入参数啊?
捏造的信仰 2007-08-24
  • 打赏
  • 举报
回复
你应当在运行的时候输入参数,比如运行:
java c03.RandomBounds lower
liky5387 2007-08-24
  • 打赏
  • 举报
回复
你在main函数里的String[] args 就能接收到以上设置的参数数据。
joejoe1991 2007-08-24
  • 打赏
  • 举报
回复
你根本就没有让程序接收输入啊。
liky5387 2007-08-24
  • 打赏
  • 举报
回复
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方法里就可以接收到你输入的参灵数.

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧