Computer Science, asked by BRAINLYSHAURYA2006, 4 months ago

Write a program in java to find the sum of the series

S = 1 + 2^2

/ a + 3^3

/ a2 + ...... to n terms​

Answers

Answered by himanshu2006vps
5

Answer:

// Java program to find the sum of the given series

import java.util.Scanner;

public class HelloWorld {

// Function to return the sum of the series

public static float getSum(int a, int n)

{

// variable to store the answer

float sum = 0;

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

// Math.pow(x, y) returns x^y

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

}

return sum;

}

// Driver code

public static void main(String[] args)

{

int a = 3, n = 3;

// Print the sum of the series

System.out.println(getSum(a, n));

}

}

Similar questions