Skip to content
Open
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
19 changes: 18 additions & 1 deletion Exercise.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
public class Exercise {

public static void main(String[] args) {
// implement exercise here
int[] one = {1, 2, 3, 4};
int[] two = {5, 6, 7, 8};
int[] both = Exercise.merge(one, two);
for (int number : both) {
System.out.println(number);
}
}

public static int[] merge(int[] first, int[] second) {
int newSize = first.length + second.length;
int[] mergedArray = new int[newSize];
for (int i = 0; i < first.length; i++) {
mergedArray[i] = first[i];
}
for (int i = 0; i < second.length; i++) {
mergedArray[i + first.length] = second[i];
}
return mergedArray;
}
}