Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
package io.zipcoder.microlabs.mastering_loops;

import java.util.ArrayList;

public class NumberUtilities {
public static String getEvenNumbers(int start, int stop) {
return null;
String evenResults = "";
for (int i = start; i < stop; i++) {
if (i % 2 == 0) {
evenResults += i;
}
}
return evenResults;
}


public static String getOddNumbers(int start, int stop) {
return null;
String oddResults = "";
for (int i = start; i < stop; i++) {
if (i % 2 != 0) {
oddResults += i;
}
}
return oddResults;
}


public static String getSquareNumbers(int start, int stop, int step) {
return null;
String squareItUpMyDude = "";
for (int i = start; i < stop; i+=step) {
int j = i * i;
squareItUpMyDude += j;
}
return squareItUpMyDude;
}


public static String getRange(int start, int stop, int step) {
return null;
String totalRange = "";
for (int i = start; i < stop; i+=step) {
totalRange += i;
}
return totalRange;
}


public static String getExponentiations(int start, int stop, int step, int exponent) {
return null;
String exponentTimeMofo = "";
for (int i = start; i < stop; i+=step) {
int j = (int)Math.round(Math.pow(i, exponent));
exponentTimeMofo += j;
}
return exponentTimeMofo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;
int width = (int)Math.floor(Math.log10(5 * 5)) + 2;
String format = "%" + width + "d |";
StringBuilder b = new StringBuilder(5 * width);
for (int row = 1; row <= 5; row++) {
for (int col = 1; col <= 5; col++) {
b.append(String.format(format, row * col));
}
b.append("\n");
}
return b.toString();
}

public static String getLargeMultiplicationTable() {
return null;
return getMultiplicationTable(10);
}

public static String getMultiplicationTable(int tableSize) {
return null;
int width = (int)Math.floor(Math.log10(tableSize * tableSize)) + 1;
String format = "%" + width + "d |";
StringBuilder b = new StringBuilder(tableSize * width);
for (int row = 1; row <= tableSize; row++) {
for (int col = 1; col <= tableSize; col++) {
b.append(String.format(format, row * col));
}
b.append("\n");
}
return b.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package io.zipcoder.microlabs.mastering_loops;

import java.lang.*;

public class TriangleUtilities {

public static String getTriangle(int numberOfRows) {
return null;
StringBuilder customTri = new StringBuilder("");
for (int i = 1; i <= numberOfRows - 1; i++) {
customTri.append(getRow(i));
customTri.append("\n");
}
return customTri.toString();
}

public static String getRow(int numberOfStars) {
return null;
StringBuilder rowStarString = new StringBuilder("");
for (int i = 0; i < numberOfStars; i++) {
rowStarString.append("*");
}
return rowStarString.toString();
}

public static String getSmallTriangle() {
return null;
return getTriangle(5);
}

public static String getLargeTriangle() {
return null;
return getTriangle(10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testGetRange2() {
@Test
public void testGetEvenNumbers() {
// : Given
String expected = "5791113151719";
String expected = "681012141618";
int start = 5;
int stop = 20;

Expand All @@ -65,10 +65,10 @@ public void testGetEvenNumbers() {
@Test
public void testGetOddNumbers() {
// : Given
String expected = "681012141618";
String expected = "5791113151719";
int start = 5;
int stop = 20;
int step = 5;
// int step = 5; <This isn't supposed to be here right?

// : When
String actual = NumberUtilities.getOddNumbers(start, stop);
Expand Down Expand Up @@ -107,6 +107,7 @@ public void testGetExponentiationNumbers() {
// : When
String actual = NumberUtilities.getExponentiations(start, stop, step, exponent);

// : Then
Assert.assertEquals(expected, actual);
}
}