-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathTableUtilities.java
More file actions
41 lines (34 loc) · 1.03 KB
/
TableUtilities.java
File metadata and controls
41 lines (34 loc) · 1.03 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
39
40
public class TableUtilities {
public static String getSmallMultiplicationTable() {
int x = 5;
String result1 = getMultiplicationTable(x);
return result1;
}
public static String getLargeMultiplicationTable() {
int y = 10;
String result2 = getMultiplicationTable(y);
return result2;
}
public static String getMultiplicationTable(int tableSize) {
String result = "";
for (int i=1; i <= tableSize; i++) {
for (int j=1; j <= tableSize; j++) {
int product = i * j;
if (product <10)
{
result += " " + product + " |";
}
else if ( product < 100 && product > 9)
{
result += " " + product + " |";
}
else
{
result += "" + product + " |";
}
}
result += "\n";
}
return result;
}
}