请问这个程序怎样编译

hubai 2002-04-04 09:23:38
import java.net.*;

public class WhoAmI{
public static void main(String[] args)
throws Exception {
if(args.length!=1){
System.err.println("Usage:WhoAmI MachinName");
System.exit(1);
}
IntAddress a=IntAddress.getByName(Args[0]);
System.out.println(a);
}
}
...全文
40 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
coollbt 2002-04-05
  • 打赏
  • 举报
回复
你先程序改成这样:把InetAddress a=InetAddress.getByName(Args[0]);改成
InetAddress a=InetAddress.getByName(args[0]);
将文件保存为WhoAmI.java
然后在命令符里输入:javac WhoAmI.java
pilishine 2002-04-05
  • 打赏
  • 举报
回复
我试了一下:
import java.net.*;

public class WhoAmI{
public static void main(String[] args)
throws Exception {
if(args.length!=1){
System.err.println("Usage:WhoAmI MachinName");
System.exit(1);
}
InetAddress a=InetAddress.getByName(args[0]);

System.out.println(a);
}
}

保存WhoAmI.java,不能编译;
public class WhoAmI->public class t;保存t.java,能编译;
运行:java t sanxia(机器名)
成功
hubai 2002-04-05
  • 打赏
  • 举报
回复
不好意思,打错了,这下能编译了,但用以下命令运行时出错
java WhoAmI 206
我的机器名206
kkhui 2002-04-04
  • 打赏
  • 举报
回复
InetAddress
woowindice 2002-04-04
  • 打赏
  • 举报
回复
import java.net.*;

public class WhoAmI{
public static void main(String[] args)
throws Exception {
if(args.length!=1){
System.err.println("Usage:WhoAmI MachinName");
System.exit(1);
}
InetAddress a=InetAddress.getByName(args[0]);

System.out.println(a);
}
}


this is right!
lyonchen 2002-04-04
  • 打赏
  • 举报
回复
import java.net.*;

public class WhoAmI{
public static void main(String[] args)
throws Exception {
if(args.length!=1){
System.err.println("Usage:WhoAmI MachinName");
System.exit(1);
}
InetAddress a=InetAddress.getByName(args[0]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.out.println(a);
}
}
hubai 2002-04-04
  • 打赏
  • 举报
回复
书上好像都是小写,<Thinking in java >510页
abitoom 2002-04-04
  • 打赏
  • 举报
回复
你是不是写错了,在main()中是args,在IntAddress.getByName()中是Args.
大小写不对.
hubai 2002-04-04
  • 打赏
  • 举报
回复
他是由java.net提供的.<Thinking in Java>(509页)有
swingcoder 2002-04-04
  • 打赏
  • 举报
回复
好像少了类:IntAddress

62,614

社区成员

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

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