Programming Examples

Java program to find the sum of the following series


Write a program to find the sum of the following series:

S=1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5)+…+(1+2+3+4+…+10)

(Please note that no nested loop is to be used)

Solution

import java.util.*;
class SUM
{
	public static void main(String arr[])
	{
		int i,s=0,p=0;
		for(i=1;i<=10;i++)
		{
			p=p+i;
			s=s+p;
		}
		System.out.println("Sum="+s);
	}	
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad