I have here a code that needs to pass all the value >= min(4)
it does the work but it also prints the empty indices.
Is there a way to remove the 0s?
this is the code, it is in Processing Java:
naisip ko kaya ganun, gawa po ng return statement, it returns the original size of the orray that's why
i think it also prints all the empty or 0 element inside the new array
it does the work but it also prints the empty indices.
Is there a way to remove the 0s?
this is the code, it is in Processing Java:
Java:
void setup() {
noLoop();
}
void draw() {
int[] test = {3, 9, -2, 6, 1, 8};
int[] result = filter(test, 4);
println(result);
}
int[] filter(int[] origArr, int min){
int[] newArr = new int[origArr.length];
for (int i=0; i<newArr.length; i++){
if (origArr[i]>=min)
newArr[i] = origArr[i];
}
return newArr;
}
Code:
/*OUTPUT*/
[0] 0
[1] 9
[2] 0
[3] 6
[4] 0
[5] 8
i think it also prints all the empty or 0 element inside the new array