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
Expand Up @@ -3,26 +3,63 @@

public class NumberUtilities {
public static String getEvenNumbers(int start, int stop) {
return null;
StringBuilder sb = new StringBuilder();
for (int i = start; i < stop; i++) {
if (i % 2 == 0) {
sb.append(i).toString();
}
}
return sb.toString();
}


public static String getOddNumbers(int start, int stop) {
return null;
StringBuilder sb = new StringBuilder();
for (int i = start; i < stop; i++) {
if (i % 2 != 0) {
sb.append(i).toString();
}
}
return sb.toString();
}


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

StringBuilder sb = new StringBuilder();

for (int i = start; i < stop; i += step) {
sb.append((int) Math.pow(i, 2));
}

return sb.toString();


}


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

StringBuilder sb = new StringBuilder();

for (int i = start; i < stop; i += step) {
sb.append(i).toString();
}

return sb.toString();

}



public static String getExponentiations(int start, int stop, int step, int exponent) {
return null;
StringBuilder sb = new StringBuilder();

for (int i = start; i < stop; i += step) {
sb.append((int) Math.pow(i, exponent));
}

return sb.toString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,56 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;

StringBuilder builder = new StringBuilder();

for (int row = 1; row <= 5; row++) {
for(int col = 1; col <=5; col++) {
int table = row * col;
builder.append(String.format("%3d |", table));

}

builder.append("\n");

}

return builder.toString();
}

public static String getLargeMultiplicationTable() {
return null;

StringBuilder builder = new StringBuilder();

for (int row = 1; row <= 10; row++) {
for(int col = 1; col <=10; col++) {
int table = row * col;
builder.append(String.format("%3d |", table));

}

builder.append("\n");

}

return builder.toString();
}

public static String getMultiplicationTable(int tableSize) {
return null;

StringBuilder builder = new StringBuilder();

for (int row = 1; row <= tableSize; row++) {
for(int col = 1; col <= tableSize; col++) {
int table = row * col;
builder.append(String.format("%3d |", table));

}

builder.append("\n");

}

return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
public class TriangleUtilities {

public static String getTriangle(int numberOfRows) {
return null;
StringBuilder builder = new StringBuilder();
for (int row = 0; row < numberOfRows; row++) {
builder.append(getRow(row));
}
return builder.toString();
}

public static String getRow(int numberOfStars) {
return null;
StringBuilder builder = new StringBuilder();

for (int i = 0; i <= numberOfStars; i++) {
builder.append("*");
}
builder.append("\n");
return builder.toString();
}

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

public static String getLargeTriangle() {
return null;
return getTriangle(9);
}
}
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,7 +65,7 @@ public void testGetEvenNumbers() {
@Test
public void testGetOddNumbers() {
// : Given
String expected = "681012141618";
String expected = "5791113151719";
int start = 5;
int stop = 20;
int step = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void getRow() {
@Test
public void getTriangleTest1() {
String expected =
"*\n" +
"*\n" +
"**\n" +
"***\n" +
"****\n" +
Expand All @@ -27,7 +27,7 @@ public void getTriangleTest1() {
"*******\n" +
"********\n" +
"*********\n";
String actual = TriangleUtilities.getTriangle(10);
String actual = TriangleUtilities.getTriangle(9);
Assert.assertEquals(expected, actual);
}

Expand Down