当我运行此代码时,它会返回 java 中的“退出状态 143”

TIG*_*UZI 5 java compiler-errors cube divide-and-conquer

当我运行这段代码时,它在java中返回“退出状态143”,我不知道那里出了什么问题,希望有人能帮助我解决这个问题。

class Main {
    static double diff(double y, double x, double d){
     if((y*y*y)+d>x)
     return ((y*y*y)+d-x);
     else return(x-(y*y*y)+d);
    }

    static double cubicRoot(double x, double d){
      double start=0 , end=x;
      double e = 0.01;
      while(true){
        double y=(start+end)/2;
        double error = diff(x,y,d);
        if (error <= e)
        return y;
        if(y*y*y+d>x)
        end =y;
        else 
        start =y;
      }
    }

      public static void main(String[] args) {

        double x =10;
        double d =0.1;
        System.out.println("root y is:" + cubicRoot(x,d));

      }
    }
Run Code Online (Sandbox Code Playgroud)

小智 8

退出代码 143 对应于 SIGTERM,这是运行 Kill 时默认发送的信号。

您或操作系统是否终止了该进程?这是你最终杀死的无限循环吗?

  • 因为您试图像“double error = diff(x,y,d);”那样调用它,并且函数定义表明您保留了错误的顺序“static double diff(double y, double x, double d)”。变量的命名并不重要,但似乎您的期望值的顺序不同 (2认同)