Computer Science, asked by tiwariaman722, 9 months ago

please
find the series in java

s=2/a + 3/a2 + 5/a3 7/a4......n​

Answers

Answered by miltonmayur
4

Answer:

Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + … + n/a^n)

Given two integers  and . The task is to find the sum of the series 1/a + 2/a2 + 3/a3 + … + n/an.

Examples:

Input: a = 3, n = 3

Output: 0.6666667

The series is 1/3 + 1/9 + 1/27 which is

equal to 0.6666667

Answered by priyanshicshah100506
4

Answer:

import java.util.Scanner;

public class KboatSeries

{

   public void computeSum() {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter a: ");

       int a = in.nextInt();

       System.out.print("Enter n: ");

       int n = in.nextInt();

       double sum = 0;

       int lastPrime = 1;

       for (int i = 1; i <= n; i++) {

           for (int j = lastPrime + 1; j <= Integer.MAX_VALUE; j++) {

               boolean isPrime = true;

               for (int k = 2; k <= j / 2; k++) {

                   if (j % k == 0) {

                       isPrime = false;

                       break;

                   }

               }

               

               if (isPrime) {

                   sum += j / Math.pow(a, i);

                   lastPrime = j;

                   break;

               }

           }

       }

       System.out.println("Sum=" + sum);

   }

}

Similar questions