Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for Arrays 07 #81

Open
wants to merge 2 commits into
base: exercises/arrays/07
Choose a base branch
from
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;
}
}