Pārlūkot izejas kodu

Updated TableUtilitiies Methods

Trinh Tong 6 gadus atpakaļ
vecāks
revīzija
780ba461d7
1 mainītis faili ar 11 papildinājumiem un 3 dzēšanām
  1. 11
    3
      TableUtilities.java

+ 11
- 3
TableUtilities.java Parādīt failu

@@ -2,14 +2,22 @@
2 2
 
3 3
 public class TableUtilities {
4 4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+        return getMultiplicationTable(5);
6 6
     }
7 7
 
8 8
     public static String getLargeMultiplicationTable() {
9
-        return null;
9
+        return getMultiplicationTable(10);
10 10
     }
11 11
 
12 12
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
13
+        StringBuilder multiTable = new StringBuilder();
14
+        // nested for loop
15
+        for (int i = 1; i <= tableSize; i++) {
16
+            for (int j = 1; j <= tableSize; j++) {
17
+                multiTable.append(String.format("%3d |", i * j));
18
+            }
19
+            multiTable.append("\n");
20
+        }
21
+        return multiTable.toString();
14 22
     }
15 23
 }