加减除都能用,乘就不能用。实在检测不出来问题来,大家帮忙看看~
public class TestArgs {public static void main(String[] args) {
for(int i=0; i<args.length; i++) {
System.out.println(args[i]);
}
System.out.println(
"Usage: java Test \"n1\" \"op\" \"n2\"");
if(args.length<3){
System.out.println(
"Usage: java Test \"n1\" \"op\" \"n2\"");
System.exit(-1);
}
double d1 = Double.parseDouble(args[0]);
double d2 = Double.parseDouble(args[2]);
double d = 0.0;
if(args[1].equals("+")) d = d1+d2;
else if(args[1].equals("-")) d = d1-d2;
else if(args[1].equals("*")) d = d1*d2;
else if(args[1].equals("/")) d = d1/d2;
else{
System.out.println("Error operator!");
System.exit(-1);
}
System.out.println(d);
}
}
错误是:8
.classpath
.project
bin
lib
src
2
Usage: java Test "n1" "op" "n2"
Exception in thread "main" java.lang.NumberFormatException: For input string: ".project"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at Array.TestArgs.main(TestArgs.java:19)
[[it] 本帖最后由 dthm 于 2008-9-24 17:22 编辑 [/it]]