Kthomas 6 anos atrás
pai
commit
fe52ffbc4c

+ 4
- 0
src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java Ver arquivo

@@ -1,6 +1,10 @@
1 1
 package io.zipcoder.microlabs.mastering_loops;
2 2
 
3 3
 public class TableUtilities {
4
+    /**
5
+     *
6
+     * @return a formatted multiplication table of various sizes
7
+     */
4 8
 
5 9
     public String getSmallMultiplicationTable() {
6 10
         StringBuilder smallTable = new StringBuilder();

+ 32
- 38
src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java Ver arquivo

@@ -3,58 +3,52 @@ package io.zipcoder.microlabs.mastering_loops;
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getTriangle(int numberOfRows) {
6
+        StringBuilder newTriangle = new StringBuilder("*\n");
7
+        StringBuilder newLine = new StringBuilder("*");
8
+        int counter = 1;
9
+        while (counter < numberOfRows - 1) {
10
+            newLine.append("*");
11
+            newTriangle.append(newLine).append("\n");
12
+            counter++;
13
+        }
6 14
 
7
-            String newTriangle = "*\n";
8
-            String newLine= "*";
9
-            int counter = 1;
10
-
11
-            while(counter < numberOfRows - 1){
12
-                 newLine += "*";
13
-                 newTriangle += newLine + "\n";
14
-                 counter++;
15
-          }
16
-         return newTriangle;
15
+        return newTriangle.toString();
17 16
     }
18 17
 
19 18
     public static String getRow(int numberOfStars) {
20
-
21
-            String star = "";
22
-            int counter = 1;
23
-
24
-            while(counter <= numberOfStars) {
25
-                star = star + "*";
26
-                counter++;
19
+        StringBuilder star = new StringBuilder();
20
+        int counter = 1;
21
+        while (counter <= numberOfStars) {
22
+            star.append("*");
23
+            counter++;
27 24
         }
28
-        return star;
25
+
26
+        return star.toString();
29 27
     }
30 28
 
31 29
     public static String getSmallTriangle() {
32
-
33
-        String newTriangle = "*\n";
34
-        String newLine = "*";
30
+        StringBuilder newTriangle = new StringBuilder("*\n");
31
+        StringBuilder newLine = new StringBuilder("*");
35 32
         int counter = 1;
36
-
37
-        while(counter < 4){
38
-            newLine += "*";
39
-            newTriangle += newLine + "\n";
33
+        while (counter < 4) {
34
+            newLine.append("*");
35
+            newTriangle.append(newLine).append("\n");
40 36
             counter++;
41 37
         }
42
-        return newTriangle;
38
+
39
+        return newTriangle.toString();
43 40
     }
44 41
 
45 42
     public static String getLargeTriangle() {
46
-
47
-            String newTriangle = "*\n";
48
-            String newLine = "*";
49
-            int counter = 1;
50
-
51
-            while(counter < 9){
52
-                newLine += "*";
53
-                newTriangle += newLine + "\n";
54
-                counter++;
43
+        StringBuilder newTriangle = new StringBuilder("*\n");
44
+        StringBuilder newLine = new StringBuilder("*");
45
+        int counter = 1;
46
+        while (counter < 9) {
47
+            newLine.append("*");
48
+            newTriangle.append(newLine).append("\n");
49
+            counter++;
55 50
         }
56
-        return newTriangle;
51
+
52
+        return newTriangle.toString();
57 53
     }
58 54
 }
59
-
60
-// woo!