Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. package Assignment2;
  2.  
  3. public class Assignment2a {
  4. public static void main(String[] args) {
  5. int result = Assignment2a.exp(2, 8);
  6. System.out.println("2^8=" + result);
  7. }
  8.  
  9. /**
  10. * Calculate of the base to the exponent
  11. *
  12. * @param base Base
  13. * @param exponent Exponent
  14. * @return Value of the base to the exponent
  15. */
  16. private static int exp(int base, int exponent) {
  17. int result = base;
  18.  
  19. for (int i = 1; i < exponent; i++) {
  20. result *= base;
  21. }
  22.  
  23. return result;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement