ソースを参照

Done with my loops

Whitney Martinez 6 年 前
コミット
2bd1a84bac
共有5 個のファイルを変更した73 個の追加47 個の削除を含む
  1. バイナリ
      .DS_Store
  2. 43
    3
      TableUtilities.java
  3. 25
    37
      TriangleUtilities.java
  4. 0
    2
      TriangleUtilitiesTest.java
  5. 5
    5
      package.bluej

バイナリ
.DS_Store ファイルの表示


+ 43
- 3
TableUtilities.java ファイルの表示

2
 
2
 
3
 public class TableUtilities {
3
 public class TableUtilities {
4
     public static String getSmallMultiplicationTable() {
4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+        String mul = "";
6
+        
7
+        
8
+        for(int i = 1; i<= 5; i++){
9
+             
10
+            int number =0;
11
+            for(int j= 1; j<=5; j++){
12
+                number = i * j;
13
+                mul += String.format("%3d |",number);
14
+            }
15
+            mul += "\n";
16
+            
17
+        }
18
+        
19
+        return mul;
6
     }
20
     }
7
 
21
 
8
     public static String getLargeMultiplicationTable() {
22
     public static String getLargeMultiplicationTable() {
9
-        return null;
23
+        String mul = "";
24
+        
25
+        for(int i = 1; i<=10;i++){
26
+            int number = 0;
27
+            
28
+            for(int j=1; j<=10;j++){
29
+                number = i*j;
30
+                mul += String.format("%3d |",number);
31
+            }
32
+            
33
+            mul += "\n";
34
+            
35
+        }
36
+        return mul;
10
     }
37
     }
11
 
38
 
12
     public static String getMultiplicationTable(int tableSize) {
39
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
40
+        String mul = "";
41
+        
42
+        for(int i = 1; i<=tableSize;i++){
43
+            int number = 0;
44
+            
45
+            for(int j=1; j<=tableSize;j++){
46
+                number = i*j;
47
+                mul += String.format("%3d |",number);
48
+            }
49
+            
50
+            mul += "\n";
51
+            
52
+        }
53
+        return mul;
14
     }
54
     }
15
 }
55
 }

+ 25
- 37
TriangleUtilities.java ファイルの表示

1
+import java.util.*;
1
 
2
 
2
 public class TriangleUtilities {
3
 public class TriangleUtilities {
3
-
4
     public static String getRow(int numberOfStars) {
4
     public static String getRow(int numberOfStars) {
5
         String line = "";
5
         String line = "";
6
-
7
-        for(int i = 0; i <= numberOfStars; i++){
8
-            line = "*"+ line;
6
+        for(int i = 0; i < numberOfStars; i++){
7
+            line += "*";
9
         }
8
         }
10
         return line;
9
         return line;
11
 
10
 
14
     public static String getTriangle(int numberOfRows) {
13
     public static String getTriangle(int numberOfRows) {
15
 
14
 
16
         String line = "";
15
         String line = "";
17
-    
18
-        for(int i=0; i < numberOfRows; i++){
19
 
16
 
20
-            for(int j=0; j <= i; j++){
21
-                line =  line + "*";
17
+        for(int i=1; i <= numberOfRows; i++){
18
+
19
+            for(int j=1; j <= i; j++){
20
+                line += "*";
22
             }
21
             }
23
-            line =  line + "/n";
22
+            line += "\n";
24
         }
23
         }
25
 
24
 
26
         return line;
25
         return line;
28
     }
27
     }
29
 
28
 
30
     public static String getSmallTriangle() {
29
     public static String getSmallTriangle() {
31
-        return null;
32
-    }
30
+        String line = "";
33
 
31
 
34
-    public static String getLargeTriangle() {
35
-        return null;
36
-    }
32
+        for(int i=1; i <= 4; i++){
37
 
33
 
38
-    public void squares() 
39
-    {
40
-        int i,j;
41
-        for(i=1; i<=5; i++)
42
-        {
43
-            for(j=1; j<=4; j++)
44
-            {
45
-                System.out.print("*");
34
+            for(int j=1; j <= i; j++){
35
+                line += "*";
46
             }
36
             }
47
-            System.out.println(" ");
37
+            line += "\n";
48
         }
38
         }
39
+
40
+        return line;
41
+
49
     }
42
     }
43
+    public static String getLargeTriangle() {
44
+        String line = "";
50
 
45
 
51
-      public void trying()
52
-        {
53
-            int i,j,k;
54
-            for(i=1; i<=5; i++)
55
-            {
56
-                for(j=4; j>=i; j--)
57
-                {
58
-                    System.out.print(" ");
59
-                }
60
-                for(k=1; k<=(2+j-1); k++)
61
-                {
62
-                    System.out.print("*");
63
-                }
64
-                System.out.println("");
46
+        for(int i=1; i <10; i++){
47
+            for(int j=1; j <= i; j++){
48
+                line += "*";
65
             }
49
             }
50
+            line += "\n";
66
         }
51
         }
52
+
53
+        return line;
67
     }
54
     }
68
 
55
 
56
+}
69
 
57
 

+ 0
- 2
TriangleUtilitiesTest.java ファイルの表示

1
- 
2
-
3
 
1
 
4
 import org.junit.Assert;
2
 import org.junit.Assert;
5
 import org.junit.Test;
3
 import org.junit.Test;

+ 5
- 5
package.bluej ファイルの表示

8
 dependency3.from=TriangleUtilitiesTest
8
 dependency3.from=TriangleUtilitiesTest
9
 dependency3.to=TriangleUtilities
9
 dependency3.to=TriangleUtilities
10
 dependency3.type=UsesDependency
10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=709
11
+editor.fx.0.height=712
12
 editor.fx.0.width=800
12
 editor.fx.0.width=800
13
-editor.fx.0.x=559
14
-editor.fx.0.y=-876
13
+editor.fx.0.x=425
14
+editor.fx.0.y=27
15
 objectbench.height=156
15
 objectbench.height=156
16
 objectbench.width=273
16
 objectbench.width=273
17
 package.divider.horizontal=0.6008583690987125
17
 package.divider.horizontal=0.6008583690987125
18
 package.divider.vertical=0.7496159754224271
18
 package.divider.vertical=0.7496159754224271
19
 package.editor.height=481
19
 package.editor.height=481
20
 package.editor.width=360
20
 package.editor.width=360
21
-package.editor.x=-129
22
-package.editor.y=-879
21
+package.editor.x=100
22
+package.editor.y=23
23
 package.frame.height=709
23
 package.frame.height=709
24
 package.frame.width=486
24
 package.frame.width=486
25
 package.numDependencies=3
25
 package.numDependencies=3