Sum Of Numbers

2 comments - Post a comment

/****** 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 */

 
This Post has 2 Comments Add your own!
Madhuri - February 6, 2010 at 12:16 PM

can anybody post in a program to calculate sum of all digits number (dynamically fed i.e. varying number of digits)..?

Madhu - April 15, 2010 at 7:40 PM

suppose i have string randomStr="SD5G6YHH"

Can anybody post in a code to trace out number of digits in the above string..??

Note :: usage of inbuilt functions too preffered

Post a Comment