/****** 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 */
Subscribe to:
Post Comments (Atom)
can anybody post in a program to calculate sum of all digits number (dynamically fed i.e. varying number of digits)..?
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