Jarrett Samuels hace 6 años
padre
commit
3a627b4f1c
Se han modificado 3 ficheros con 152 adiciones y 21 borrados
  1. 61
    13
      NumberUtilities.java
  2. 42
    4
      TableUtilities.java
  3. 49
    4
      TriangleUtilities.java

+ 61
- 13
NumberUtilities.java Ver fichero

@@ -1,32 +1,80 @@
1
- 
2 1
 
3 2
 
4 3
 public class NumberUtilities {
5
-    
4
+
6 5
     public static String getRange(int start) {
7
-        return null;
6
+
7
+        String concatloops = "";
8
+
9
+        for (int i=0; i < start; i++) {
10
+            concatloops += "" + i;
11
+        }
12
+
13
+        return concatloops;
8 14
     }
9
-    
15
+
10 16
     public static String getRange(int start, int stop) {
11
-        return null;
12
-    }
17
+        String concatloops = "";
13 18
 
19
+        while (start < stop) {
20
+            concatloops += "" + start;
21
+            start++;
22
+        };
23
+
24
+        return concatloops;
25
+    }
14 26
 
15 27
     public static String getRange(int start, int stop, int step) {
16
-        return null;
28
+        int num = start;
29
+        String concatloops = "";
30
+
31
+        while (num < stop) {
32
+            concatloops += "" + num;
33
+            num = num + step;
34
+        }
35
+
36
+        return concatloops;
17 37
     }
18
-    
38
+
19 39
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
21
-    }
40
+        String concatloops = "";
22 41
 
42
+        while (start < stop) {
23 43
 
24
-    public static String getOddNumbers(int start, int stop) {
25
-        return null;
44
+            if ((start % 2) == 0) {
45
+                concatloops += "" + start; }
46
+
47
+            start++;
48
+        };
49
+        return concatloops;
26 50
     }
27 51
 
52
+    public static String getOddNumbers(int start, int stop) {
53
+        String concatloops = "";
54
+
55
+        while (start < stop) {
56
+
57
+            if ((start % 2) != 0) {
58
+                concatloops += "" + start; }
59
+
60
+            start++;
61
+        };
62
+        return concatloops;
63
+    }
28 64
 
29 65
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
66
+        int counter = start;
67
+        double num = start;
68
+        String concatloops = "";
69
+
70
+        while (counter <= stop) {
71
+        num = Math.pow(counter, exponent);
72
+        concatloops += "" + (int)num;
73
+        counter++;
74
+                    }
75
+
76
+        System.out.println(concatloops);
77
+
78
+        return concatloops;
31 79
     }
32 80
 }

+ 42
- 4
TableUtilities.java Ver fichero

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

+ 49
- 4
TriangleUtilities.java Ver fichero

@@ -3,19 +3,64 @@
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+    int counter = 1;
7
+    String triangle = "";
8
+    String add = "*";
9
+
10
+    for (int i = 1; i <= numberOfStars; i++){
11
+     triangle = triangle + add;
12
+    }
13
+    return triangle;
7 14
     }
8 15
     
9 16
     public static String getTriangle(int numberOfRows) {
10
-        return null;
17
+    int counter = 1;
18
+    String triangle = "";
19
+    String add = "*";
20
+
21
+    for (int i = 1; i <= numberOfRows; i++){
22
+
23
+     for (int y = 1; y <= counter; y++){
24
+     triangle = triangle + add;
25
+      }
26
+      counter++;
27
+     triangle = triangle + System.getProperty("line.separator");
28
+    }
29
+    return triangle;
11 30
     }
12 31
 
13 32
 
14 33
     public static String getSmallTriangle() {
15
-        return null;
34
+    int width = 4;
35
+    int counter = 1;
36
+    String triangle = "";
37
+    String add = "*";
38
+
39
+    for (int i = 1; i <= width; i++){
40
+
41
+     for (int y = 1; y <= counter; y++){
42
+     triangle = triangle + add;
43
+      }
44
+      counter++;
45
+     triangle = triangle + System.getProperty("line.separator");
46
+    }
47
+    return triangle;
16 48
     }
17 49
 
18 50
     public static String getLargeTriangle() {
19
-        return null;
51
+    int width = 9;
52
+    int counter = 1;
53
+    String triangle = "";
54
+    String add = "*";
55
+
56
+    for (int i = 1; i <= width; i++){
57
+
58
+     for (int y = 1; y <= counter; y++){
59
+     triangle = triangle + add;
60
+      }
61
+      counter++;
62
+     triangle = triangle + System.getProperty("line.separator");
63
+    }
64
+    return triangle;
20 65
     }
21 66
 }