-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRaiseToPower.java
More file actions
30 lines (22 loc) · 949 Bytes
/
RaiseToPower.java
File metadata and controls
30 lines (22 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//Receive the Base number from the user
//Receive the Power number from the user
//Declare an integer variable as result and initialize it with 1.
//(It will be multiplied with the base number multiple times in relation the power number).
//Declare an integer variable as whileController and initialize it with 1, it'll serve as the loop continuation condition
//whileController will also serve as the increment
import java.util.Scanner;
public class RaiseToPower {
public static void main (String[] args) {
Scanner keyboardInput = new Scanner(System.in);
System.out.print("Enter the Base number: ");
int base = keyboardInput.nextInt();
System.out.print("Enter the Base number: ");
int power = keyboardInput.nextInt();
int result = 1, whileController = 1;
while (whileController <= power) {
result = result * base;
whileController++;
}
System.out.printf("The power of %d = %d", base, result);
}
}