115. JAVA Program to Compute the 1+3+6+10+ …….+n Series.
How does this program work?
- This program is used to find the Sum of the given series 1+3+6+10+ …….+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 given series upto nth term.
Here is the code
//To Find the Sum of given series 1+3+6+10+.....+n
import java.util.Scanner;public class series
{
public static void main(String[] args )
{
int n, sum = 0;
System.out.println("Given series:1+ 3 +6+10......... +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+1)/2;
}
System.out.println("series is:"+sum );
}
}