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

 

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

Write a method that has an input parameter called 'num' which can be any integer. The method returns the sum of the digits in 'num', but this time it doesn't stop until that sum is a single digit. For example, passing in 99 returns 9 since 9+9=18 then 1+8=9. Look at the test data for further examples. Please note: NO STRING METHODS ARE ALLOWED in your solution! You MAY do this recursively but it is not required. Also, you MAY use a helper method. VERY IMPORTANT NOTE: Your method must work for ANY integer, so passing in -99 should also result in a 9. Passing in 0 results in 0.


drWhoNumberGameAdvanced2(-427482) → 9
drWhoNumberGameAdvanced2(42984421) → 7
drWhoNumberGameAdvanced2(98214789) → 3

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

public int drWhoNumberGameAdvanced2(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: 370

Copyright Nick Parlante 2017 - privacy