From ff0d6f2942bf4f09393f94a887ca374863dbb0ae Mon Sep 17 00:00:00 2001 From: Jordan Elderidge Date: Mon, 12 Feb 2018 06:37:05 -0500 Subject: [PATCH 1/2] well --- .../mastering_loops/NumberUtilities.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) 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..a8b1d48 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java @@ -3,21 +3,47 @@ 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 start, int stop) { @@ -26,7 +52,15 @@ public static String getRange(int start, int stop) { 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(); + } From 8a82d0241c06665c1c9f6a05cdfc7bcbb72fdeec Mon Sep 17 00:00:00 2001 From: Jordan Elderidge Date: Thu, 15 Feb 2018 13:18:12 -0500 Subject: [PATCH 2/2] Done --- .../mastering_loops/NumberUtilities.java | 38 ++++++++++--- .../mastering_loops/TableUtilities.java | 34 ++++++++++-- .../mastering_loops/TriangleUtilities.java | 51 ++++++++++++++++-- .../microlabs/mastering_loops/.DS_Store | Bin 0 -> 6148 bytes .../mastering_loops/NumberUtilitiesTest.java | 4 +- 5 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 src/test/java/io/zipcoder/microlabs/mastering_loops/.DS_Store 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 a8b1d48..8e0f30b 100644 --- a/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java +++ b/src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java @@ -5,7 +5,7 @@ public class NumberUtilities { public static String getEvenNumbers(int start, int stop) { StringBuilder even = new StringBuilder(); for (int i = start; i < stop; i++) { - if (i % 2 == 0) { + if (i % 2 != 0) { even.append(i); } @@ -40,14 +40,33 @@ public static String getSquareNumbers(int start, int stop, int step) { } - public static String getRange(int start) { + public static String getRange(int stop) { + StringBuilder range1 = new StringBuilder(); + for (int i =0; i < stop; i++) { + + range1.append(i); + + + } + return range1.toString(); + + - return null; } 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(); + + + } @@ -55,7 +74,7 @@ public static String getRange(int start, int stop, int step) { StringBuilder rangeNum = new StringBuilder(); for (int i = start; i < stop; i += step) { - rangeNum.append(i); + rangeNum.append(i); } @@ -65,6 +84,13 @@ public static String getRange(int start, int stop, int step) { 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 H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0