willieshi232

Untitled

Apr 18th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. /**
  2. * Created by WillieShi on 4/18/2016.
  3. */
  4. public class Recursion
  5. {
  6. public static int exponent(int baseNum, int power) {
  7.  
  8. if (power == 0)
  9. {
  10. return 1;
  11. } else {
  12. if (power % 2 == 0)
  13. {
  14. baseNum = baseNum * 2;
  15. power = power / 2;
  16. }
  17. return baseNum * exponent(baseNum, power - 1);
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment