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,65 @@

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 squareNum = new StringBuilder();

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

}
return squareNum.toString();
}


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

StringBuilder range = new StringBuilder();

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


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

for (int i = start; i < stop; i += step){
if (i < stop){
int expo = (int) Math.pow(i,exponent);
expoNum.append(expo);
}
}
return expoNum.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

public class TableUtilities {
public static String getSmallMultiplicationTable() {
return null;
StringBuilder multiTable = new StringBuilder();
for (int i = 1; i < 6; i++){
for (int j = 1; j < 6; j++){
multiTable.append(String.format("%3d |", i * j));
}
multiTable.append("\n");
}
return multiTable.toString();
}

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

public static String getMultiplicationTable(int tableSize) {
return null;
StringBuilder multiTable = new StringBuilder();
for (int i = 1; i < tableSize + 1; i++){
for (int j = 1; j < tableSize + 1; j++){
multiTable.append(String.format("%3d |", i * j));
}
multiTable.append("\n");
}
return multiTable.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,55 @@
public class TriangleUtilities {

public static String getTriangle(int numberOfRows) {
return null;
StringBuilder smallTri = new StringBuilder();

String star = "*";

for (int i = 1; i < numberOfRows; i++){
for (int j = 0; j < i; j++) {
smallTri.append(star);
}
smallTri.append("\n");
}
return smallTri.toString();
}

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

String asterisk = "*";

for (int i = 0; i < numberOfStars; i++){
stars.append(asterisk);
}
return stars.toString();
}

public static String getSmallTriangle() {
return null;
StringBuilder smallTri = new StringBuilder();

String star = "*";

for (int i = 1; i < 5; i++){
for (int j = 0; j < i; j++) {
smallTri.append(star);
}
smallTri.append("\n");
}
return smallTri.toString();
}

public static String getLargeTriangle() {
return null;
StringBuilder smallTri = new StringBuilder();

String star = "*";

for (int i = 1; i < 10; i++){
for (int j = 0; j < i; j++) {
smallTri.append(star);
}
smallTri.append("\n");
}
return smallTri.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ public void testGetRange2() {


@Test
public void testGetEvenNumbers() {
public void testGetOddNumbers() {
// : Given
String expected = "5791113151719";
int start = 5;
int stop = 20;

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

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

@Test
public void testGetOddNumbers() {
public void testGetEvenNumbers() {
// : Given
String expected = "681012141618";
int start = 5;
int stop = 20;
int step = 5;

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

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