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

 

sept26_2019_HL_strangeSum


Write a method that returns the "strange sum" of a non-negative integer parameter. The "strange sum" is the sum of the original number plus all of the numbers you get when you recursively divide the input parameter by 2 and call "strange sum" on that result. For example, the "strange sum" of 20 is 38 because 20+10+5+2+1=38. The 10 came from integer-dividing 20 by 2. The 5 came from 10/2. The 2 came from 5/2. The 1 came from 2/2. Look at the test data for further examples. Your solution MUST be recursive.


sept26_2019_HL_strangeSum(0) → 0
sept26_2019_HL_strangeSum(1) → 1
sept26_2019_HL_strangeSum(2) → 3

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

public int sept26_2019_HL_strangeSum(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: 490

Copyright Nick Parlante 2017 - privacy