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
31 lines (26 loc) · 917 Bytes
/
TableUtilities.java
File metadata and controls
31 lines (26 loc) · 917 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
31
public class TableUtilities {
public static String getSmallMultiplicationTable() {
return getMultiplicationTable(5);
}
public static String getLargeMultiplicationTable() {
return getMultiplicationTable(10);
}
public static String getMultiplicationTable(int tableSize) {
StringBuilder sb = new StringBuilder();
for(int i = 1; i <= tableSize; i++){
for(int j = 1; j <= tableSize;j++){
int product = (i * j);
sb.append(String.format("%3d |",product));
/*if(i < 10){
sb.append(" " + (i * j) + " |");
} else if (10 <= j && j < 100){
sb.append(" " + (i * j) + " |");
} else {
sb.append((i * j) + " |");
}*/
}
sb.append("\n");
}
return sb.toString();
}
}