diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java index 7d979d2..8e0f30b 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java @@ -3,34 +3,94 @@ public class NumberUtilities { public static String getEvenNumbers(int start, int stop) { - return null; + StringBuilder even = new StringBuilder(); + for (int i = start; i < stop; i++) { + if (i % 2 != 0) { + even.append(i); + } + + } + return even.toString(); } public static String getOddNumbers(int start, int stop) { - return null; - } + StringBuilder odd = new StringBuilder(); + for (int i = start; i < stop; i++) { + if (i % 2 == 0) { + odd.append(i); + } + + } + return odd.toString(); + + } public static String getSquareNumbers(int start, int stop, int step) { - return null; + StringBuilder squared = new StringBuilder(); + for (int i = start; i < stop; i += step) { + + squared.append(i * i); + + + } + + return squared.toString(); + } - public static String getRange(int start) { - return null; + public static String getRange(int stop) { + StringBuilder range1 = new StringBuilder(); + for (int i =0; i < stop; i++) { + + range1.append(i); + + + } + return range1.toString(); + + + + } public static String getRange(int start, int stop) { - return null; + StringBuilder range = new StringBuilder(); + for (int i = start; i < stop; i++) { + + range.append(i); + + + } + return range.toString(); + + + } public static String getRange(int start, int stop, int step) { - return null; + StringBuilder rangeNum = new StringBuilder(); + for (int i = start; i < stop; i += step) { + + rangeNum.append(i); + + + } + return rangeNum.toString(); + } public static String getExponentiations(int start, int stop, int step, int exponent) { - return null; + StringBuilder old = new StringBuilder(); + for (int i = start; i < stop; i += step) { + + old.append(i * i); + } + return old.toString(); } } + + diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java index e27a826..7e09b5a 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java @@ -1,15 +1,43 @@ package io.zipcoder.microlabs.mastering_loops; +import com.sun.javafx.binding.StringFormatter; + public class TableUtilities { public static String getSmallMultiplicationTable() { - return null; + StringBuilder smallMulti = new StringBuilder(); + for (int h = 1; h <6; h++){ + for (int w=1; w <6; w++){ + smallMulti.append(String.format("%3d |", w*h)); + } + smallMulti.append("\n"); + } + + return smallMulti.toString(); } public static String getLargeMultiplicationTable() { - return null; + StringBuilder multi = new StringBuilder(); + for (int h =1; h < 11; h++){ + for (int w =1; w <11; w++){ + multi.append(String.format("%3d |", w*h)); + + } + multi.append("\n"); + } + return multi.toString(); + } public static String getMultiplicationTable(int tableSize) { - return null; + StringBuilder multiTable = new StringBuilder(); + for (int h =1; h < 21; h++){ + for (int w =1; w <21; w++){ + multiTable.append(String.format("%3d |", w*h)); + + } + multiTable.append("\n"); + } + return multiTable.toString(); + } } diff --git a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java index 0c7cd35..d83a76c 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java @@ -3,18 +3,61 @@ public class TriangleUtilities { public static String getTriangle(int numberOfRows) { - return null; + StringBuilder triangle = new StringBuilder(); + for (int row =1; row