瀏覽代碼

Updated Triangle methods

Trinh Tong 6 年之前
父節點
當前提交
5e4b44f28f
共有 1 個檔案被更改,包括 4 行新增31 行删除
  1. 4
    31
      TriangleUtilities.java

+ 4
- 31
TriangleUtilities.java 查看文件

@@ -11,9 +11,7 @@ public class TriangleUtilities {
11 11
             stars.append("*"); 
12 12
         }
13 13
         
14
-        String starTriangle = stars.toString();
15
-        
16
-        return starTriangle;
14
+        return stars.toString();
17 15
     }
18 16
     
19 17
     public static String getTriangle(int numberOfRows) {
@@ -26,39 +24,14 @@ public class TriangleUtilities {
26 24
             stars.append("\n");
27 25
         }
28 26
         
29
-        String starTriangle = stars.toString();
30
-        return starTriangle;
31
-        
27
+        return stars.toString();        
32 28
     }
33 29
 
34
-
35 30
     public static String getSmallTriangle() {
36
-        StringBuilder stars = new StringBuilder();
37
-        
38
-        for (int i = 1; i < 5; i++) {
39
-            for (int j = i; j > 0; j--) {
40
-                stars.append("*");
41
-            }
42
-            stars.append("\n");
43
-        }
44
-        
45
-        String starTriangle = stars.toString();
46
-        return starTriangle;
47
-
31
+        return getTriangle(4);
48 32
         }
49 33
 
50 34
     public static String getLargeTriangle() {
51
-        StringBuilder stars = new StringBuilder();
52
-        
53
-        for (int i = 1; i < 10 ; i++) {
54
-            for (int j = i; j > 0; j--) {
55
-                stars.append("*");
56
-            }
57
-            stars.append("\n");
58
-        }
59
-        
60
-        String starTriangle = stars.toString();
61
-        return starTriangle;
62
-
35
+        return getTriangle(9);
63 36
     }
64 37
 }