Sum of series in java
1+(1*2)+2(1*2*3) n term
Answers
Answered by
15
Question:-
- WAP in JAVA to print the sum of the series
1+(1*2)+2(1*2*3)+... ... +nth term
Answer:-
//Java program to print the sum of series
package Programmer;
import java.util.*;
public class Ser{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
System.out.println("Enter a limit");
int n=sc.nextInt();
int s=1;
for(int i=1;i<=(n-1) ;i++)
s+=i*(i*(i+1));
System.out.println("Sum="+s);
}
}
Variable Description:-
- s:- sum variable
- I:- loop variable
- n:- limit variable
Attachments:
Similar questions