Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. package com.company;
  2. import java.util.Locale;
  3. public class Fff {
  4.     public static void main(String[] args) {
  5.         boolean IsCorrect = true, Repeat = true;
  6.         Double EPS = 0.0, X = 0.0, S1, S2, P = 0.0, Powww, Check;
  7.         int n = 0;
  8.         java.util.Scanner enter = new java.util.Scanner(System.in).useLocale(Locale.US);
  9.         do {
  10.             try {
  11.                 IsCorrect = true;
  12.                 System.out.println("Enter X ( X > -1 )");
  13.                 X = Double.parseDouble(enter.next());
  14.                 if (X<=-1) {
  15.                     IsCorrect = false;
  16.                     System.out.println("Incorrect X. Try again");
  17.                 }
  18.             } catch (NumberFormatException ignore) {
  19.                 System.out.println("Input the number!");
  20.                 IsCorrect = false;
  21.             }
  22.         } while (!IsCorrect);
  23.         do {
  24.             try {
  25.                 IsCorrect = true;
  26.                 System.out.println("Enter  EPS ( 0 < EPS < 1)");
  27.                 EPS = Double.parseDouble(enter.next());
  28.                 if ((EPS > 1) || (EPS <= 0)) {
  29.                     IsCorrect = false;
  30.                     System.out.println("Incorrect EPS. Try again");
  31.                 }
  32.             } catch (NumberFormatException ignore) {
  33.                 System.out.println("Input the number!");
  34.                 IsCorrect = false;
  35.             }
  36.         } while (!IsCorrect);
  37.         while (IsCorrect) {
  38.             Powww = 1.0;
  39.             if (n > 0) {
  40.                 for (int i = 0; i <= n; i++) {
  41.                     Powww = Powww * X;
  42.                 }
  43.                 S2 = (Powww / (n + 1));
  44.                 S1 = ((Powww / X) / n);
  45.                 Check = S2 - S1;
  46.                 if (Check < 0) {
  47.                     Check = -(Check);
  48.                 }
  49.                 if (Check >= EPS) {
  50.                     IsCorrect = true;
  51.                     n++;
  52.                     if ((n) % 2 == 0) {
  53.                         P = P - S2;
  54.                     } else {
  55.                         P = P + S2;
  56.                     }
  57.                 } else {
  58.                     IsCorrect = false;
  59.                 }
  60.             } else {
  61.                 P = X;
  62.                 n++;
  63.             }
  64.         }
  65.         System.out.format("LN(1+X)= %.5f%n", P);
  66.         System.out.println("N= " + (n));
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement