public class PowerWithIteration { public static void main (String[] argv) { int p = power (3, 2); System.out.println ( "3^2 = " + p); p = power (3, 4); System.out.println ( "3^4 = " + p); p = power (2, 8); System.out.println ( "2^8 = " + p); } static int power (int a, int b) { int p = 1; // a^0 while (b > 0) { p = p * a; // b times through loop. b --; } return p; } }