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,62 @@
package io.zipcoder.microlabs.mastering_loops;

import java.lang.*;

public class NumberUtilities {
public static String getEvenNumbers(int start, int stop) {
return null;


StringBuilder evenNum = new StringBuilder();
for (int i = start; i < stop; i++) {
if (i % 2 == 0) {
evenNum.append(i);
}
}
return evenNum.toString();
}


public static String getOddNumbers(int start, int stop) {
return null;

StringBuilder oddNum = new StringBuilder();
for (int i = start; i <= stop; i++) {
if (i % 2 != 0) {
oddNum.append(i);
}
}
return oddNum.toString();
}


public static String getSquareNumbers(int start, int stop, int step) {
return null;

StringBuilder sqNum = new StringBuilder();

for (int i = start; i < stop; i+=step) {
sqNum.append(Math.round(Math.pow(i, 2)));
}
return sqNum.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 exponentNum = new StringBuilder();

for (int i = start; i < stop; i+=step) {
exponentNum.append(Math.round(Math.pow(i, exponent)));
}
return exponentNum.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package io.zipcoder.microlabs.mastering_loops;

public class TableUtilities {

public static String getSmallMultiplicationTable() {
return null;

return getMultiplicationTable(5);
}

public static String getLargeMultiplicationTable() {
return null;

return getMultiplicationTable(10);
}

public static String getMultiplicationTable(int tableSize) {
return null;
StringBuilder matrix = new StringBuilder();

for(int row = 1; row <= tableSize; row++) {
for(int col = 1; col <= tableSize; col++){
matrix.append(String.format("%3d |", row * col));
}
matrix.append("\n");
}
return matrix.toString();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,38 @@
public class TriangleUtilities {

public static String getTriangle(int numberOfRows) {
return null;

String triangleContainer = "";

for (int row=1; row < numberOfRows; row++)
{
for (int column=0; column<row; column++)
{
triangleContainer += "*";
}
triangleContainer += "\n";
}
return triangleContainer;
}

public static String getRow(int numberOfStars) {
return null;

String triangleContainer = "";

for (int row=0; row < numberOfStars; row++)
{
triangleContainer += "*";
}
return triangleContainer;
}

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,9 @@ public void testGetEvenNumbers() {
@Test
public void testGetOddNumbers() {
// : Given
String expected = "681012141618";
String expected = "5791113151719";
int start = 5;
int stop = 20;
int step = 5;

// : When
String actual = NumberUtilities.getOddNumbers(start, stop);
Expand Down