|
@@ -3,45 +3,47 @@ package io.zipcoder.microlabs.mastering_loops;
|
3
|
3
|
public class TableUtilities {
|
4
|
4
|
|
5
|
5
|
public String getSmallMultiplicationTable() {
|
6
|
|
-
|
7
|
|
- String lilguy = "";
|
8
|
|
- for(int i = 1; i < 6; i++) {
|
9
|
|
- String grow = "";
|
10
|
|
- for (int a = 1; a < 6; a++) {
|
11
|
|
- int b = a * i;
|
12
|
|
- grow += String.format("%3d", b) + " |";
|
13
|
|
- }
|
14
|
|
- lilguy += grow + "\n";
|
|
6
|
+ StringBuilder smallTable = new StringBuilder();
|
|
7
|
+ for (int i = 1; i < 6; i++) {
|
|
8
|
+ StringBuilder grow = new StringBuilder();
|
|
9
|
+ for (int a = 1; a < 6; a++) {
|
|
10
|
+ int b = a * i;
|
|
11
|
+ grow.append(String.format("%3d", b)).append(" |");
|
15
|
12
|
}
|
16
|
|
- return lilguy;
|
|
13
|
+
|
|
14
|
+ smallTable.append(grow).append("\n");
|
|
15
|
+ }
|
|
16
|
+
|
|
17
|
+ return smallTable.toString();
|
17
|
18
|
}
|
18
|
19
|
|
19
|
20
|
public String getLargeMultiplicationTable() {
|
20
|
|
-
|
21
|
|
- String bigguy = "";
|
22
|
|
- for(int i = 1; i < 11; i++) {
|
23
|
|
- String grow = "";
|
|
21
|
+ StringBuilder bigTable = new StringBuilder();
|
|
22
|
+ for (int i = 1; i < 11; i++) {
|
|
23
|
+ StringBuilder grow = new StringBuilder();
|
24
|
24
|
for (int a = 1; a < 11; a++) {
|
25
|
25
|
int b = a * i;
|
26
|
|
- grow += String.format("%3d", b) + " |";
|
|
26
|
+ grow.append(String.format("%3d", b)).append(" |");
|
27
|
27
|
}
|
28
|
|
- bigguy += grow + "\n";
|
|
28
|
+
|
|
29
|
+ bigTable.append(grow).append("\n");
|
29
|
30
|
}
|
30
|
|
- return bigguy;
|
|
31
|
+
|
|
32
|
+ return bigTable.toString();
|
31
|
33
|
}
|
32
|
34
|
|
33
|
35
|
public String getMultiplicationTable(int tableSize) {
|
34
|
|
-
|
35
|
|
- String ultraguy = "";
|
|
36
|
+ StringBuilder table = new StringBuilder();
|
36
|
37
|
for (int i = 1; i < 21; i++) {
|
37
|
|
- String grow = "";
|
|
38
|
+ StringBuilder grow = new StringBuilder();
|
38
|
39
|
for (int a = 1; a < 21; a++) {
|
39
|
40
|
int b = a * i;
|
40
|
|
- grow += String.format("%3d", b) + " |";
|
|
41
|
+ grow.append(String.format("%3d", b)).append(" |");
|
41
|
42
|
}
|
42
|
|
- ultraguy += grow + "\n";
|
43
|
|
- }
|
44
|
43
|
|
45
|
|
- return ultraguy;
|
|
44
|
+ table.append(grow).append("\n");
|
46
|
45
|
}
|
|
46
|
+
|
|
47
|
+ return table.toString();
|
47
|
48
|
}
|
|
49
|
+}
|