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

 

crazyBase


Write a method that accepts a positive integer called origNum and a base from 2 to 10 called base. The method returns origNum converted to base, but it returns it as a long. None of the test data will cause a number too big for long. (Remember that long is just like int only it can hold larger values). Note that if base is 10 your method will simply return origNum. For example, crazyBase(19,2) will return 10011 as a long... but this is really representing the binary number 10011 in base 2, which is equivalent to 19 in base 10. Look at the test data for additional samples. NOTE: I solved this problem in one line of code on my first try, so DON'T overcomplicate things! (Of course I also used a tertiary conditional with a recursive solution). Your solution is not required to be recursive and you may have a longer bit of code if needed... I just wanted you to realize that it does not have to be super complicated.


crazyBase(98, 7) → 200
crazyBase(32, 2) → 100000
crazyBase(35, 2) → 100011

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

public long crazyBase(int origNum, int base) { }

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

Copyright Nick Parlante 2017 - privacy