Write a Java Program to Calculate the Power of a Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class Main { class Main { public static void main(String[] args) { int base = 3, exponent = 4; long result = 1; while (exponent != 0) { result *= base; --exponent; } System.out.println("Answer = " + result); } } |
1 thought on “Write a Java Program to Calculate the Power of a Number”