【问题标题】:When I run this code it return that "exit status 143" in java当我运行此代码时,它会在 java 中返回“退出状态 143”
【发布时间】:2020-02-28 19:00:50
【问题描述】:

当我运行此代码时,它在 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));

      }
    }

【问题讨论】:

  • 当我开始运行程序时,输出屏幕上什么也没有返回,几分钟后它返回“退出状态 143”
  • static double diff(double y, double x, double d){ - 我确定您的订单有误。应该是static double diff(double x, double y, double d)
  • 是的,先生,您是对的,您能告诉我为什么会这样吗?@JohannesKuhn

标签: javascript java compiler-errors cube divide-and-conquer


【解决方案1】:

退出码 143 对应 SIGTERM,即运行 kill 时默认发送的信号。

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

【讨论】:

  • 有人为我修复了它,因为 void 中的变量顺序错误。但是为什么会发生我的意思是为什么我不能像“double y, double x, double d”这样写
  • 因为你试图像double error = diff(x,y,d); 一样调用它,而函数定义表明你的顺序是错误的`static double diff(double y, double x, double d)`。变量的命名并不重要,但您的预期值似乎是不同的顺序
猜你喜欢
  • 2017-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 1970-01-01
相关资源
最近更新 更多