/* RaiseToPower: doing exponentiation using a "for" loop */ // a generalized for loop import javax.swing.JOptionPane; public class RaiseToPower { public static void main( String[] args ) { int base, exponent; int result = 1; // Prompt the user to enter the base String numString1 = JOptionPane.showInputDialog(null, "What is the base? ", "Input Number Window", JOptionPane.QUESTION_MESSAGE); // Convert the string into an int value base = Integer.parseInt(numString1); // Prompt the user to enter the exponent String numString2 = JOptionPane.showInputDialog(null, "What is the exponent? ", "Input Number Window", JOptionPane.QUESTION_MESSAGE); // Convert the string into an int value exponent = Integer.parseInt(numString2); // "for" loop for(int index = 1; index <= exponent; index++) { result *= base; } System.out.println(base + " to the power of " + exponent + " is " + result); System.exit( 0 ); } // end main } // end of program