Browse Source

refactoring old labs is fun

Carolynn Vansant 6 years ago
parent
commit
b5ae6b4656

BIN
.DS_Store View File


+ 7
- 26
src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java View File

@@ -5,53 +5,34 @@ public class NumberUtilities {
5 5
 
6 6
     public static String getEvenNumbers(int start, int stop) {
7 7
         String evens = "";
8
-        int count = start;
9
-        if((count / 2) != 0) {
10
-            count += 1;
11
-        }
12
-        for(int i = count; i < stop; i+=2) {
13
-            evens = evens + i;
14
-        }
8
+        if(start%2 != 0)  start += 1;
9
+        for(int i = start; i < stop; i+=2)  evens += i;
15 10
         return evens;
16 11
     }
17 12
 
18
-
19 13
     public static String getOddNumbers(int start, int stop) {
20 14
         String odds = "";
21
-        int count = start;
22
-        if((count / 2) == 0) {
23
-            count += 1;
24
-        }
25
-        for(int i = count; i < stop; i+=2) {
26
-            odds += i;
27
-        }
15
+        if(start %2 == 0) start += 1;
16
+        for(int i = start; i < stop; i+=2)  odds += i;
28 17
         return odds;
29 18
     }
30 19
 
31
-
32 20
     public static String getSquareNumbers(int start, int stop, int step) {
33 21
         String square = "";
34
-        for(int i = start; i < stop; i+=step) {
35
-            square += (i*i);
36
-        }
22
+        for(int i = start; i < stop; i+=step) square += (i*i);
37 23
         return square;
38 24
     }
39 25
 
40
-
41 26
     public static String getRange(int start, int stop, int step) {
42 27
         String xEach = "";
43
-        for(int i = start; i < stop; i+=step){
44
-            xEach += i;
45
-        }
28
+        for(int i = start; i < stop; i+=step) xEach += i;
46 29
         return xEach;
47 30
     }
48 31
 
49
-
50 32
     public static String getExponentiations(int start, int stop, int step, int exponent) {
51 33
         String expo = "";
52 34
         for(int i = start; i< stop; i+=step){
53
-            expo += (int)(Math.pow(i, exponent));
54
-        }
35
+            expo += (int)(Math.pow(i, exponent)); }
55 36
         return expo;
56 37
     }
57 38
 }

+ 0
- 1
src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java View File

@@ -25,7 +25,6 @@ public class TableUtilities {
25 25
             }
26 26
             large += multiply + "\n";
27 27
         }
28
-
29 28
         return large;
30 29
     }
31 30
 

+ 1
- 1
src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java View File

@@ -18,7 +18,7 @@ public class TriangleUtilities {
18 18
         String aster = "";
19 19
         int counter = 1;
20 20
         while(counter <= numberOfStars) {
21
-            aster = aster + "*";
21
+            aster += "*";
22 22
             counter++;
23 23
         }
24 24
         return aster;