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

 

gaurav.gupta@mq.edu.au recursion > singleDigitSumRecursive
prev  |  next  |  chance

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.


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

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

int singleDigitSumRecursive(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: 2 Post-solution available

Copyright Nick Parlante 2017 - privacy