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

 

test2023_06_01_APP1SL_recursiveSumProcess


Write a method that returns the sum of 'num' plus all the "halves" of 'num'. For example, if 'num' is 20 you would return 38 because 20+10+5+2+1=38. Note that when you take half of each number you are using integer division, so you ignore anything after the decimal point. Here are some other examples and reasons for the answers: The "halves sum" of 53 is 102 because 53+26+13+6+3+1=102 You MUST solve this USING recursion. Your solution must be a RECURSIVE solution! I suggest making a recursive helper method with a much shorter name, then just return the result of calling that method. Of course you will have to write that recursive helper method too! However, use of a helper method is NOT required. Preconditions: num>=1


test2023_06_01_APP1SL_recursiveSumProcess(28) → 53
test2023_06_01_APP1SL_recursiveSumProcess(100) → 197
test2023_06_01_APP1SL_recursiveSumProcess(67) → 131

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

public int test2023_06_01_APP1SL_recursiveSumProcess(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: 310

Copyright Nick Parlante 2017 - privacy