SHARE
TWEET

Untitled

a guest Jun 6th, 2017 290 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package calculationsMethod;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static double func(double x) {
  8.         return (x * x * x) - 2 * x + 7;
  9.     }
  10.  
  11.  
  12.     public static void main(String[] args) {
  13.         Scanner scanner = new Scanner(System.in);
  14.         final double EPSILON = scanner.nextDouble();
  15.         double a = -2.5, b = -2.0, x1 = 0;
  16.         while (Math.abs(a - b) > EPSILON) {
  17.             x1 = (a + b) / 2;
  18.             if (func(x1) <= 0) {
  19.                 break;
  20.             } else if (func(x1) * func(a) < 0) {
  21.                 b = x1;
  22.             } else {
  23.                 a = x1;
  24.             }
  25.         }
  26.         System.out.println((a + b) / 2);
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top