114. JAVA Program to Compute the 1+8+27+64+ …….+n Series.
How does this program work?
- This program is used to find the Sum of the given series 1+8+27+64+ …….+n using java.
- The integer entered by the user is stored in variable n i.e., last term for the given series.
- Declare variable sum and Initially initialize with 0.
- By using for loop we can find the sum of series for cube of numbers upto nth term.
Here is the code
//To Find the Sum of given series 1+8+27+64+ …….+n
import java.util.Scanner;public class series
{
public static void main(String[] args )
{
int n, sum = 0;
System.out.println("Series:1+ 8 +27+64......... +n");
System.out.print("Enter value of n:\n");
Scanner skill = new Scanner(System.in);
n = skill.nextInt();
for ( int i = 1; i <= n; i++ )
{
sum = sum+ ( i*i*i );
}
System.out.println("Sum of cube series is:"+sum);
}
}