Write a java program to generate the following series.
( 1 ) (1+2)2+ (1+2+3)3+(1+2+3+4)4+…….(1+2+3+……..+n)n
(2) SUM=(1)+(1+2)+(1+2+3)+(1+2+3+4)…n
(3) SUM=1/1!+2/2!+3/3!+4/4!+5/5!....n
Answers
Answered by
2
import java.util.*;
public class n
{
static int sumOfSeries(int n)
{
int sum = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
sum += j;
return sum;
}
public static void main String args [])
{
Scanner sc=new Scanner(System.in);
System.out.print("Please enter a number: ");
int n = sc.nextInt();
System.out.println(sumOfSeries(n));
sc.close();
}
}
Similar questions