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

 

jebbert@volusia.k12.fl.us > test2021_04_08_SLHL_digitEvenSum
prev  |  next  |  chance

Write a method that recursively computes the "digit sum" of the given number, by following these rules: #1: The digit sum is computed recursively until a single-digit answer is obtained. #2: The digit sum is found by adding all the digits in the number, except odd digits are "promoted" to the next even digit. For example, the sum of the digits of 134 would be 2+4+4=10 (because the 1 gets promoted to a 2 and the 3 gets promoted to a 4). However, this is not a single-digit answer, so the process is repeated with 10. The sum of those digits is 2 (because the 1 gets promoted to a 2, and 2+0=2). This IS a single digit, so that value, 2, is the result. Look at the test data for further examples. Your solution is allowed to use one loop, but at least part of your solution must be done recursively.


test2021_04_08_SLHL_digitEvenSum(24126489) → 4
test2021_04_08_SLHL_digitEvenSum(99999) → 6
test2021_04_08_SLHL_digitEvenSum(20000) → 2

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

public int test2021_04_08_SLHL_digitEvenSum(int num) { }

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: 290

Copyright Nick Parlante 2017 - privacy