fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. static double f(double x)
  8. {
  9. return 9.2*x*x*x+3.3*x*x+4*x-1;
  10. }
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Scanner in = new Scanner(System.in);
  15. double x, eps, x0, x1, x2, d;
  16. x = in.nextDouble();
  17. eps = in.nextDouble();
  18. do{
  19. x0=x;
  20. x1=f(x0);
  21. x2=f(x1);
  22. d=x0-2*x1+x2;
  23. if (d!=0)
  24. {
  25. x=(x0*x2-x1*x1)/d;
  26. }
  27. else break;
  28. }
  29. while(Math.abs(x-x0)>eps);
  30. System.out.print(x+" ");
  31. }
  32. }
Success #stdin #stdout 0.17s 321344KB
stdin
-4 0.0005
stdout
-3.999806151275519