赞助连接

赞助连接

阅 读 文 章

麻烦大家给看一下这个程序问什么报错呀,谢谢

[来源:网上转载 (http://bbs.chinaunix.net) | 作者:网友(网络转载) | 时间:2008-06-12 | 浏览: 人次 ]

我是新手,麻烦大家给看一下。请问下面这个程序问什么编译时报错找不到d1和d2呀。先谢谢各位了。

public class TestA {
public static void main(String[] args) {
  if(args.length < 3) {
   System.out.println("Usage: java TestArgs \"n1\" \"op\" \"n2\"");
   System.exit(-1);
  }
  try {
   double d1 = Double.parseDouble(args[0]);
  } catch (NumberFormatException e) {
   e.printStackTrace();
  }
  try {
   double d2 = Double.parseDouble(args[2]);
  } catch (NumberFormatException e) {
   e.printStackTrace();
  }
  double d = 0;
  
  if(args[1].equals("+")) {
   d = d1 + d2;
  } else if (args[1].equals("-")) {
   d = d1 - d2;
  } else if (args[1].equals("x")) {
   d = d1 * d2;
  } else if (args[1].equals("/")) {
   d = d1 / d2;
  } else {
   System.out.println("Error operator!");
   System.exit(-1);
  }
  System.out.println(d);
}
}


因为你的 d1 和d2 都在 try {}里面,所以 d1 和d2 都必须声明为在try{}外面。。。。。。。。。。。。。。。!@


哦,我明白了,谢谢你了,非常感谢。


TAG标签 : 谢谢 程序 这个 大家 麻烦 d2 d1 args if else .equals

最新评论 共有0位网友发表了评论

发表评论

评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名:(注册)
密码:
验证码:
匿名发表
网站地图友情连接交流论坛网站投稿广告服务联系我们留言本站长统计
Some rights reserved: www.newhtm.com, 鄂ICP备07010232号 E-mail:chinakafei@live.com,QQ:552766
中国咖啡技术网(Chmhome):国外编程技术书籍,中文编程手册,经典编程文章,交流技术,技术软件下载,计算机论文,毕业论文.