Question: / * * * * * * * * * * * * * * * * * * * * * * * *
Power.java
Reads in two integers and uses a recursive power method
to compute the first raised to the second power.
import java.util.Scanner;
public class Power
public static void mainString args
int base, exp;
int answer;
Scanner scan new ScannerSystemin;
System.out.printWelcome to the power program! ;
System.out.printlnPlease use integers only.";
get base
System.out.printEnter the base you would like raised to a power: ;
base scan.nextInt;
get exponent
System.out.printEnter the power you would like it raised to: ;
exp scan.nextInt;
answer power baseexp;
System.out.printlnbase raised to the exp is answer;
Computes and returns baseexp
public static int powerint base, int exp
int pow;
if the exponent is set pow to
otherwise set pow to basebaseexp
return pow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
