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
15 changes: 12 additions & 3 deletions src/main/java/com/booleanuk/core/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,28 @@ public Exercise(int age) {
provided to the name and age members
*/


public Exercise(String s, int i) {
this.name = s;
this.age = i;
}

/*
2. Create a method named add that accepts two integers. The method should return the numbers added together.
*/

public int add(int a, int b){
int number;
return number = a + b;
}



/*
3. Create another method named add that accepts two Strings. The method should return the strings concatenated
together with a space in between.
*/


public String add (String a, String b) {
return a + " " + b;
}

}
57 changes: 57 additions & 0 deletions src/main/java/com/booleanuk/extension/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,63 @@ public class Extension extends ExtensionBase {
E.g.
multiply(["2", "7", "3"], 3) -> [6, 21, 9]
*/
public float add(float a, float b) {
return a + b;
}

public double add (double a, double b){
return a + b;
}

public float subtract(float a, float b) {
return a - b;
}

public String subtract (String a, char b) {
String newString = a.replaceAll(String.valueOf(b), "");
return newString;
}

public int multiply(int a, int b) {
return a * b;
}

public String multiply (String a, int b) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < b; i++) {
result.append(a);
if (i < b - 1) {
result.append(",");
}
}
return result.toString();
}

public int[] multiply (String[] strings, int b) {
int[] newArray = new int[b];
int i = 0;
for (String a : strings){
newArray[i] = (Integer.parseInt(a) * b);
i++;
}
return newArray;
}

}





/*

7. multiply, which accepts an array of Strings that each contain a number, and an int
The method should return an array of ints that contain the value of multiplying each String number by the provided int
E.g.
multiply(["2", "7", "3"], 3) -> [6, 21, 9]*/






Loading