Sunday, 23 September 2012

Sum Of Numbers

/****** Java Program To Print Sum Of 'n' Number ******/

class Add
{
public static void main (String args[])
{
int n = 15;
int sum = 0;
for(int i = n;i>=0;i--)
sum = sum + i;
System.out.println("Sum = "+ sum);
}
}

/*************** OUTPUT *************
* *
* Sum = 120 */

0 comments:

Post a Comment