I have one code that does the correct elements and one that does the correct array and I can't quite get the two ideas to combine.

given int[] myArray = {9, 22, 333, 400, 5005, 1}; getInRange(myArray, 100, 1000) should return the int[ ] {333, 400}

public class Main {
public static void main(String[] args) {
// you may wish to write some code in this main method
// to test your method.
}

public static int[] getInRange(int myArray[], int j, int k) {
int i;
int[] newArray = new int[myArray.length];
for(i = 0; i < myArray.length; ++i) {
if((myArray[i] > j) && (myArray[i] < k)) {
newArray[i] = myArray[i];
}
}
return newArray;
}
}

FAIL - incorrect output
expected :

{333, 400}

but got :

{0, 0, 333, 400, 0, 0}

public class Main {
public static void main(String[] args) {
// you may wish to write some code in this main method
// to test your method.
}

public static int[] getInRange(int myArray[], int j, int k) {
int i;
int count = 0;
for(i = 0; i < myArray.length; ++i) {
if((myArray[i] > j) && (myArray[i] < k)) {
count = count + 1;
}
}
int[] newArray = new int[count];
for(i = 0; i < newArray.length; ++i) {
if(myArray[i] < 0) {
newArray[i] = myArray[i];
}
}
return newArray;
}
}

FAIL - incorrect output
expected :

{333, 400}

but got :

{0, 0}