This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.