|
@@ -1,15 +1,63 @@
|
1
|
|
-
|
|
1
|
+import java.lang.StringBuilder;
|
2
|
2
|
|
3
|
3
|
public class TableUtilities {
|
4
|
4
|
public static String getSmallMultiplicationTable() {
|
5
|
|
- return null;
|
|
5
|
+
|
|
6
|
+ StringBuilder sb = new StringBuilder();
|
|
7
|
+
|
|
8
|
+ for (int i = 1; i < 6; i++) {
|
|
9
|
+ for (int j = 1; j < 6; j++) {
|
|
10
|
+ int product = i*j;
|
|
11
|
+ sb.append(" ");
|
|
12
|
+ if (product < 10) {
|
|
13
|
+ sb.append(" ");
|
|
14
|
+ }
|
|
15
|
+ sb.append(product + " |");
|
|
16
|
+ }
|
|
17
|
+ sb.append("\n");
|
|
18
|
+ }
|
|
19
|
+ return sb.toString();
|
6
|
20
|
}
|
7
|
21
|
|
8
|
22
|
public static String getLargeMultiplicationTable() {
|
9
|
|
- return null;
|
|
23
|
+
|
|
24
|
+ StringBuilder sb = new StringBuilder();
|
|
25
|
+
|
|
26
|
+ for (int i = 1; i < 11; i++) {
|
|
27
|
+ for (int j = 1; j < 11; j++) {
|
|
28
|
+ int product = i*j;
|
|
29
|
+ sb.append(" ");
|
|
30
|
+ if (product < 10) {
|
|
31
|
+ sb.append(" ");
|
|
32
|
+ } else if (product > 99) {
|
|
33
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
34
|
+ }
|
|
35
|
+ sb.append(product + " |");
|
|
36
|
+ }
|
|
37
|
+ sb.append("\n");
|
|
38
|
+ }
|
|
39
|
+ System.out.println(sb.toString());
|
|
40
|
+ return sb.toString();
|
10
|
41
|
}
|
11
|
42
|
|
12
|
43
|
public static String getMultiplicationTable(int tableSize) {
|
13
|
|
- return null;
|
|
44
|
+
|
|
45
|
+ StringBuilder sb = new StringBuilder();
|
|
46
|
+
|
|
47
|
+ for (int i = 1; i < tableSize + 1; i++) {
|
|
48
|
+ for (int j = 1; j < tableSize + 1; j++) {
|
|
49
|
+ int product = i*j;
|
|
50
|
+ sb.append(" ");
|
|
51
|
+ if (product < 10) {
|
|
52
|
+ sb.append(" ");
|
|
53
|
+ } else if (product > 99) {
|
|
54
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
55
|
+ }
|
|
56
|
+ sb.append(product + " |");
|
|
57
|
+ }
|
|
58
|
+ sb.append("\n");
|
|
59
|
+ }
|
|
60
|
+ System.out.println(sb.toString());
|
|
61
|
+ return sb.toString();
|
14
|
62
|
}
|
15
|
63
|
}
|