// **************************************************************** // Power.java // // Reads in two integers and uses a recursive power method // to compute the first raised to the second power. // **************************************************************** import java.io.*; public class Power { public static void main(String[] args) throws IOException { int base, exp; int answer; BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Welcome to the power program! "); System.out.println("Please use integers only."); //get base System.out.print("Enter the base you would like raised to a power: "); base = Integer.parseInt(keyboard.readLine()); //get exponent System.out.print("Enter the power you would like it raised to: "); exp = Integer.parseInt(keyboard.readLine()); answer = power(base,exp); System.out.println(base + " raised to the " + exp + " is " + answer); } // ------------------------------------------------- // Computes and returns base^exp // ------------------------------------------------- public static int power(int base, int exp) { int pow; // if the exponent is 0, set pow to 1 // otherwise set pow to base*base^(exp-1) // return pow } }