Print Sum of series 1+ (1+2) + (1+2+3)……. (1+2+3+…….n) in Java
import java.util.Scanner;
public class Series
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of terms ");
int n = sc.nextInt();
int sum = 0, i = 0;
for (int j = 1; j <= n; j++)
{
for (i = 1; i <= j; i++)
{
sum = sum + i;
}
i = 1;
}
System.out.println("Sum of series = " + sum);
}
}
Output:
Enter the no of terms
4
Sum of series = 20
BUILD SUCCESSFUL (total time: 2 seconds)
Java Resources are available for Download from below
Category: Core Java, Interview Question, Programs, Series, Written Test
Very helpfull dude .Thankxxx👍👍👌
ReplyDeleteThnkss dear very
ReplyDeletevery helpful🤗🤗
can you please send the same program in java .io
ReplyDeleteThanks for the above solution..
ReplyDeleteJust a little doubt I have
As to how should I print the series?
Thanks again!
Thank you for this solution
ReplyDelete