id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

singleDigitSum


Define a function that when passed an integer, returns the single-digit sum of its digits. For example, if n = 999999997, the sum of the digits is 79, but since its not a single-digit number, we compute the sum of its digits, which is 16. It's still not a single-digit number, so we repeat the process, finally yielding 7.


singleDigitSum(999999997) → 7
singleDigitSum(39) → 3
singleDigitSum(100) → 1

...Save, Compile, Run (ctrl-enter)

int singleDigitSum(int n) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 3 Post-solution available

Copyright Nick Parlante 2017 - privacy