4

When I run this code it return that "exit status 143" in java, I don't know what's going wrong there, hope someone can help me fix this problem.

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));

      }
    }
moffeltje
  • 4,521
  • 4
  • 33
  • 57
TIGUZI
  • 231
  • 1
  • 3
  • 12

1 Answers1

7

Exit code 143 corresponds to SIGTERM, which is the signal sent by default when you run kill .

Did you or the OS kill the process? Is it an infinite loop that you eventually killed?

AndyMan
  • 397
  • 1
  • 7
  • Someone fixed it for me it caused because the variable order in the void was wrong. But why it is happened I mean why I can't write it like "double y, double x, double d" – TIGUZI Nov 03 '19 at 04:05
  • 2
    Because you are trying to call it like `double error = diff(x,y,d);` and function definition suggest that you have kept the order wrong ` static double diff(double y, double x, double d)`. Naming of variable doesn't really matter but it seems your expected values are in different order – www.hybriscx.com Nov 03 '19 at 04:58