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

 

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

Without using recursion, and without using the Math library, write a method that uses a loop to calculate the result of taking 'base' to the 'power'. For example, if 'base' is 5 and 'power' is 3 the result would be 125 because 5 to the third power is 125. As preconditions, you may assume that base and power will both be non-negative. Please note that these results can get very large, so 'int' is not big enough to store your result. Use 'long' instead. This is just like 'int' except that it can store larger numbers. Remember: Do NOT use recursion nor the Math class.


exponent(7, 12) → 13841287201
exponent(10, 15) → 1000000000000000
exponent(0, 8) → 0

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

public long exponent(int base, int power) { }

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

Copyright Nick Parlante 2017 - privacy