-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintTable.java
More file actions
28 lines (22 loc) · 919 Bytes
/
PrintTable.java
File metadata and controls
28 lines (22 loc) · 919 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
//Declare and initialize two int vaiables "a" and "b" with 0 and 1 respectively.
//Display a string showing the header in the question a, b, pow(a, b).
//Use loop to set a condition for variable "a" to increase 5 time also set variable "b" to increase.
//Use the built in raise to power method to get the power of "a^b" then allow loop repeat it. for all a and b values.
//Save the raise to power value in a double variable.
//Convert double to int.
//Display the looped value of "a", "b" and int converted power in one print statement using tab to space them properly.
public class PrintTable {
public static void main (String[] args) {
int a = 0, b = 1;
System.out.println("a\tb\tpow(a, b)");
double power;
int castedFloats;
while (a != 5) {
a++;
b++;
power = (Math.pow(a, b));
castedFloats = (int) power;
System.out.printf("%d \t%d \t%d\n", a, b, castedFloats);
}
}
}