Java program

Mar 28, 2010 at 1:38pm
Does anyone knows how to write this exercise?

Write a program that reads a number, then calculates and displays the sum-of-digits. It should work for all numbers from 0 to 9999 (6 points).
The sum-of-digits is the sum of all digits of an integer.
sumOfDigits(1234) = 1 + 2 + 3 + 4 = 10
sumOfDigits(387) = 3 + 8 + 7 = 18
The output should look as follows (if the number is 2372):
Please enter a number: 2372
The sum-of-digits is 14
Mar 28, 2010 at 2:17pm
Yes, I know.
Mar 28, 2010 at 2:23pm
Topic archived. No new replies allowed.