一个数组小练习编译通过,运行出错!在myeclipse 上没有显示错误信息
代码如下,请协助!package part1;public class TestArray {
public static void main(String[] args) {
if(args.length<3){
System.out.println("error length,pls. re-enter !");
System.exit(-1);
}

double d1 = Double.parseDouble(args[0]);
double d3 = Double.parseDouble(args[2]);
double d0 = 0;

if(args[1].equals("+")){
d0 = d1+d3;
}else if(args[1].equals("-")){
d0 = d1-d3;
}else if(args[1].equals("x")){
d0 = d1*d3;
}else if(args[1].equals("/")){
d0 = d1/d3;
}else{
System.out.println("error oprator,pls.re-enter!");
System.exit(-1);
}
System.out.println(d0);
}}

解决方案 »

  1.   

    You can run it in DOS comm. of your computer and it will shows the error message, pls. help to me and tell me the reason is better,
    Thanks!
      

  2.   


        public static void main(String[] args) {
    args=new String[3];
    args[0]="1";
    args[1]="+";
    args[2]="3";
            if(args.length<3){
      

  3.   

    编译没问题而运行时有问题,那应该是运行时异常的问题,像数组溢出、零值除数都会报这样的RuntimeException
      

  4.   

    错误图片<a href="http://tinypic.com?ref=nxp1yq" target="_blank"><img src="http://i54.tinypic.com/nxp1yq.jpg" border="0" alt="Image and video hosting by TinyPic"></a>
      

  5.   

    应该是
    java part1.TestArray 3 - 5
      

  6.   

    java part1.TestArray 10 - 5
    参数之间需要用空格
      

  7.   

    编译的时候:javac -d . TestArray.java
    运行的时候:java part1.TestArray 2 + 5
    这样应该没错。