I have a lab where I ask the user for a number(x) then ask them for a power(p). I need to return (x^p) as a BigInteger but I am having some trouble doing this. I have working code for a Int but the number gets to large and I need to use a BigInteger. Any insight would be greatly appreciated. Thanks.
It seems more elegant to me than looping, but why exactly is it a better implementation. In case I have a big exponent I could run into a StackOverflowError, which won't happen using a loop.
Joined: Oct 13, 2005
It is better to use recursion because he will get more marks for it. The idea behind these things is to demonstrate they know algorithms and techniques. I have a recursive method, too, which (of course) has to use BigInteger.multiply.