Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- import java.lang.Math;
- public class Main {
- public static void main(String[] args) {
- Scanner inConsole = new Scanner(System.in);
- System.out.print("Введите число n = ");
- int n = inConsole.nextInt();
- while (n == 0) {
- System.out.print("ОШИБКА! Введит чило n>0 = ");
- n = inConsole.nextInt();
- }
- System.out.print("Введите число x = ");
- double x = inConsole.nextDouble();
- System.out.println(counterSUM(n, x));
- System.out.print(" Введите e = ");
- double e = inConsole.nextDouble();
- while (e > 1) {
- System.out.print("ОШИБКА! Введите е<1: ");
- e = inConsole.nextDouble(); }
- System.out.println(counterSumWithE(e, x));
- System.out.println(counterSumWithE(e / 10, x));
- System.out.print(counterSumWithMath(x));
- }
- static double parameters (double fraction , int i, double x) {
- fraction = fraction * x / i;
- return fraction;
- }
- static double counterSUM(int n, double x) {
- double first = 1;
- double amount = 0;
- for (int i = 1; i <= n; i++) {
- amount += first;
- first = parameters (first, i, x);
- }
- return amount;
- }
- static double counterSumWithE(double e, double x) {
- double fractionNew = 1;
- int k = 1;
- double amount = 0;
- while (Math.abs(parameters(fractionNew, k, x)) > e ) {
- amount += fractionNew;
- k++;
- fractionNew = parameters(fractionNew, k, x);
- }
- return amount;
- }
- static double counterSumWithMath(double x) {
- return Math.pow(Math.E, x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement