forked from Zipcoder/BlueJ.NumbersTrianglesTables
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableUtilities.java
More file actions
38 lines (35 loc) · 1.13 KB
/
TableUtilities.java
File metadata and controls
38 lines (35 loc) · 1.13 KB
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
31
32
33
34
35
36
37
38
public class TableUtilities {
public static String getSmallMultiplicationTable() {
String string = "";
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= 5; j++) {
String cell = String.format("%3s |",i * j);
string = string + cell;
}
string = string + "\n";
}
return string;
}
public static String getLargeMultiplicationTable() {
StringBuilder sb = new StringBuilder();
for(int i = 1; i <= 10; i++) {
for(int j = 1; j <= 10; j++) {
String cell = String.format("%3s |",i * j);
sb.append(cell);
}
sb.append("\n");
}
return sb.toString();
}
public static String getMultiplicationTable(int tableSize) {
StringBuilder sb = new StringBuilder();
for(int i = 1; i <= tableSize; i++) {
for(int j = 1; j <= tableSize; j++) {
String cell = String.format("%3s |",i * j);
sb.append(cell);
}
sb.append("\n");
}
return sb.toString();
}
}