#
Java Program – Sum of Series 1+2+3+4+….+10

This program computes the sum of the series 1+2+3+4+…+10. It can be easily modified to compute the sum over a larger range.

// SumSeries series
// 1 + 2 + 3 + 4 + 5 + 6 + .... + 10
// ANS: 55
// Mukesh Tekwani
class SumSeries
{
public static void main(String args[]) //args is an array or a collection
{
int sum = 0;
int i; //counter variable
int n;
//java SumSeries 10 // "10" is stored in args[0]
n = Integer.parseInt(args[0]); //function name ---> parseInt parse ---> scan/understand
// n = 10
for (i = 1; i <= n; i++)
{
sum = sum + i;
}
System.out.println("Sum of series is : " + sum);
}
}

### Share this with your friends:

### Like this:

Like Loading...