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 @@ -4,38 +4,119 @@
public class NumberUtilities {

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

// Initialize an empty string to hold result
String result="";

// Iterate through the range from start to stop with the given step
// step skips by 5 so it should be 5,10,15
for (int i=start;i<stop;i=i+step){

// use Math.pow to calculate the exponentiation of i
//use double because expected includes decimal values
double doubleResult=Math.pow(i,exponent);

//convert double to string
result = result + String.valueOf(doubleResult);
}
//return result
return result;
}

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

// Initialize an empty string to hold result
String result="";

// Iterate through the range from start to stop with the given step
for (int i = start; i < stop; i += step) {
result = result + i;
}

//return result
return result;

}

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

// Initialize an empty string to hold result
String result="";

// Iterate through the range from start to stop (include 'start' -> set equal and exclude 'stop' ->not equal)
for (int i=start;i<stop;i++) {
result = result + i;
}
//return result
return result;
}

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

// Initialize an empty string to hold result
String result="";

// Iterate through the range from 0 to stop
for (int i=0; i<stop;i++) {
result = result + i;
}

//return result
return result;
}

/*
* natural break
*/

public static boolean isNumberEven(int toTest) { return false; }
public static boolean isNumberOdd(int toTest) { return false; }

public static boolean isNumberEven(int toTest) { return toTest % 2 == 0; } //test even

public static boolean isNumberOdd(int toTest) { return toTest % 2 != 0; } //test odd

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

// Initialize an empty string to hold result
String result = "";

// Iterate through the range from start to stop (include 'start' -> set equal and exclude 'stop' ->not equal)
for (int i = start; i < stop; i++) {
if (i % 2 == 0) {
result = result + i;
}
}
//return result
return result;
}


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

// Initialize an empty string to hold result
String result = "";

// Iterate through the range from start to stop (include 'start' -> set equal and exclude 'stop' ->not equal)
for (int i = start; i < stop; i++) {
if (i % 2 != 0) {
result = result + i;
}
}
//return result
return result;
}


public static String getSquareNumbers(int start, int stop, int step) {
return null;
// Initialize an empty string to hold result
String result = "";

// Iterate through the range from start to stop with the given step
// step skips by 5 so it should be 5,10,15
for (int i = start; i < stop; i += step) {
result = result + (i * i);
}
//return result
return result;
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
package io.zipcoder.microlabs.mastering_loops;

public class TableUtilities {

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

//Create variable table to hold empty string
String table = "";

//Create outer loop for ROWS -> R => the amound of rows needed
//Iterate from 1 to tableSize (including tableSize)
for (int r = 1; r <= tableSize; r++) {

//Create inner loop for COLUMNS -> C => the amount of columns needed
for (int c = 1; c <= tableSize; c++) {

//Multiply the row and columns to get the total for the table size
//(how many times do the rows and columns intersect?)
int valueOfTableSize = r * c;

//If number is less than 10, add 2 spaces before the number
//and a | to the end
if (valueOfTableSize < 10) {
table = table + " " + valueOfTableSize + " |";
} else if (valueOfTableSize < 100) {
//If number is less than 100, add one space before the number
//add a | to the end
table = table + " " + valueOfTableSize + " |";
} else {
//If number is greater than 100, no need to add spaces
//add a | to the end
table = table + valueOfTableSize + " |";
}
}
// Add a newline at the end of each row -> \n
table = table + "\n";
}
//Return the table
return table;
}


public static String getSmallMultiplicationTable() {
return null;

//call the getMultiplicationTable method with 5 to get 5 rows and 5 columns
return getMultiplicationTable(5);
}

public static String getLargeMultiplicationTable() {
return null;

//call the getMultiplicationTable method with 10 to get 10 rows and 10 columns
return getMultiplicationTable(10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,48 @@
public class TriangleUtilities {

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

// Initialize an empty string to hold the row of stars
String result = "";

// Use a while loop until the number of stars is reached
int i = 1;
while (i <= numberOfStars) {
result = result + '*';
i = i + 1;
}
//result = result + '\n';
return result;

}

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

// Initialize an empty string to hold the triangle
String result="";

// Use a while loop to build the triangle row by row
int i=1;
while (i<numberOfRows) {
result=result+getRow(i);
// Add a newline character after each row
result = result + '\n';
i++;
}
// return the amount of rows
return result;
}

// hmm

public static String getSmallTriangle() {
return null;

//Set to 4 because in previous function we had to add an extra row
return getTriangle(5);
}

public static String getLargeTriangle() {
return null;

//Set to 10 because in previous function we had to add an extra row
return getTriangle(10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void testGetRange3C() {
@Test
public void testGetEvenNumbers() {
// : Given
String expected = "5791113151719";
String expected = "681012141618";
int start = 5;
int stop = 20;

Expand All @@ -198,7 +198,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 Expand Up @@ -231,7 +231,7 @@ public void testGetSquareNumbers() {
@Test
public void testGetExponentiationNumbers() {
// : Given
String expected = "25100225";
String expected = "25.0100.0225.0";
int start = 5;
int stop = 20;
int step = 5;
Expand Down