Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Locale;
- public class Fff {
- public static void main(String[] args) {
- boolean IsCorrect = true, Repeat = true;
- Double EPS = 0.0, X = 0.0, S1, S2, P = 0.0, Powww, Check;
- int n = 0;
- java.util.Scanner enter = new java.util.Scanner(System.in).useLocale(Locale.US);
- do {
- try {
- IsCorrect = true;
- System.out.println("Enter X ( X >= 0 )");
- X = Double.parseDouble(enter.next());
- if (X<-3) {
- IsCorrect = false;
- System.out.println("Incorrect X. Try again");
- }
- } catch (NumberFormatException ignore) {
- System.out.println("Input the number!");
- IsCorrect = false;
- }
- } while (!IsCorrect);
- do {
- try {
- IsCorrect = true;
- System.out.println("Enter EPS ( 0 < EPS < 1)");
- EPS = Double.parseDouble(enter.next());
- if ((EPS > 1) || (EPS <= 0)) {
- IsCorrect = false;
- System.out.println("Incorrect EPS. Try again");
- }
- } catch (NumberFormatException ignore) {
- System.out.println("Input the number!");
- IsCorrect = false;
- }
- } while (!IsCorrect);
- while (IsCorrect) {
- Powww = 1.0;
- if (n > 0) {
- for (int i = 0; i <= n; i++) {
- Powww = Powww * X;
- }
- S2 = (Powww / (n + 1));
- S1 = ((Powww / X) / n);
- Check = S2 - S1;
- if (Check < 0) {
- Check = -(Check);
- }
- if (Check >= EPS) {
- IsCorrect = true;
- n++;
- if ((n) % 2 == 0) {
- P = P - S2;
- } else {
- P = P + S2;
- }
- } else {
- IsCorrect = false;
- }
- } else {
- P = X;
- n++;
- }
- }
- System.out.format("LN(1+X)= %.5f%n", P);
- System.out.println("N= " + (n));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement