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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz