Posted by Anonymous on Wed 10th Jan 21:13 (modification of post by Anonymous view diff)
diff | download | new post
- public int sumDigits(int n)
- {
- int returnValue = 0; // our return value
- for (int i=0;i<num.length();i++) // We want to cycle through each character
- {
- returnValue += Integer.parseInt(num.substring(i,i)); // get just one character, aka one of the numbers and add it to the returnValue
- }
- return returnValue; // return our value
- }
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.