forked from mirandaio/codingbat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake2.java
More file actions
26 lines (23 loc) · 702 Bytes
/
make2.java
File metadata and controls
26 lines (23 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Given 2 int arrays, a and b, return a new array length 2 containing, as
* much as will fit, the elements from a followed by the elements from b. The
* arrays may be any length, including 0, but there will be 2 or more
* elements available between the 2 arrays.
*/
public int[] make2(int[] a, int[] b) {
int[] arr = new int[2];
int count = 0;
int i;
i = 0;
while(count < 2 && i < a.length) {
arr[count] = a[i];
count++;
i++;
}
i = 0;
while(count < 2 && i < b.length) {
arr[count] = b[i];
count++;
i++;
}
return arr;
}