Computer Science, asked by Harsh07102006, 3 months ago

wap in java to input the sum of a + a^2 + a^3.........................................+a^n

Answers

Answered by samarthkrv
0

Answer:

import java.util.Scanner;

import java.lang.Math;

public class Main

{

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.print("Enter the value for a:");

    int a = sc.nextInt();

 System.out.print("Enter value of n in the series :");

 int n = sc.nextInt();

 double sum = 0;

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

         int ind = 1;

         sum = sum + (Math.pow(n,ind) + Math.pow(n,(ind+1)));

         ind += 2;

     }

 System.out.println("The sum of the series is "  + (int)sum);

}

}

Explanation:

Similar questions