Java program to find sum of first n numbers



Code

package com.candidjava.code;

class SumOfNum
{
	public static void main(String args[])
	{
		int sum = 0;
		int n=10;
		for(int i = 1;i <= n;i++)
		{
			sum = sum + i;
		}
		System.out.println("The Sum Of "+n+" Numbers are:" + sum);
	}
}


Output

The Sum Of 10 Numbers are:55




Related Post

Comments

vr
         nice

©candidjava.com