Advertisement
Guest User

4.2

a guest
Oct 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package proj1;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class P42
  7. {
  8. private static final double eps = (double) 1E-15 ;
  9. public static void main(String[] args)
  10. {
  11. Scanner in = new Scanner(System.in);
  12. System.out.println ("a = ");
  13. double a = in.nextInt();
  14. System.out.println ("b = ");
  15. double b = in.nextInt();
  16. System.out.println ("c = ");
  17. double c = in.nextInt();
  18. System.out.println ("x0 = ");
  19. double x = in.nextInt();
  20. double y = x - (a*x*x+b*x+c)/(2*a*x+b) ;
  21. int k = 1;
  22. while (y - x < eps )
  23. {
  24. x = y ;
  25. y = x - (a*x*x+b*x+c)/(2*a*x+b) ;
  26. k ++;
  27. }
  28. System.out.println ( "Xn = " + x +'\n' + "Xn+1 = " + y);
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement