首页 新闻 会员 周边

java中的简单计算器,为何*号不能运算,其他的加减除可以,难道‘*’有特殊含义

0
[待解决问题]

package MainTest;

public class Computer {
public static void main(String[] args) {
if(args.length<3){
System.out.println("plese read n1 op n2");
System.exit(-1);
}
double n1 = Double.parseDouble(args[0]);
double n2 = Double.parseDouble(args[2]);
double d=0;
if(args[1].equals("+")){
d=n1 + n2;
}else if(args[1].equals("-")){
d=n1 - n2;
}else if(args[1].equals("/")){
d=n1/n2;
}else if(args[1].equals("*")){
d=n1*n2;
}else{
System.out.println("error");
System.exit(-1);
}
System.out.println(d);
}
}

海阔天空lyj的主页 海阔天空lyj | 菜鸟二级 | 园豆:202
提问于:2016-12-06 09:52
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册