Hello can someone show me how to incorporate my method integerPower into the main? I want it to be able to take in the values the user inputs and calculate the value.
here is the code I have so far:
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int base;
int exponent;
System.out.printf("Enter base value: ");
base = input.nextInt();
System.out.printf("Enter the exponent value:");
exponent = input.nextInt();
}
public static int integerPower(int base, int exponent) {
int i = 0, p = 1;
while (i < exponent) {
p = p * base;
i++;
}
return p;
}
}
import java.util.Scanner; public class TestCode { public static void main(String[] args) { Scanner input = new Scanner(System.in); int base; int exponent; System.out.printf("Enter base value: "); base = input.nextInt(); System.out.printf("Enter the exponent value:"); exponent = input.nextInt(); int result = integerPower(base,exponent); System.out.println("Result = "+result); } public static int integerPower(int base, int exponent) { int i = 0, p = 1; while (i < exponent) { p = p * base; i++; } return p; } }
Get Answers For Free
Most questions answered within 1 hours.