This is my attempt at this problem, how would I move the 0's to the end of the array? I tried swapping the 0 elements with the end elements and well that wasn't it...
public void removeMiddle() {
int pos = values.length/2;
int n = values.length
if (n%2 == 0) {
int fMid = pos - 1;
values[pos] = 0;
values fMid = 0;
} else {
int j = n-1;
int k = j/2;
int l = k+1;
int m = n-l;
values[m] = 0;
}
}
Array = {5, 2, 7, 9, 1, 3, 2, 4}
result = [5, 2, 7, 0, 0, 3, 2, 4]
Expected: [5, 2, 7, 3, 2, 4, 0, 0]
Array = {5, 2, 7, 9, 1, 3, 2}
result = [5, 2, 7, 0, 1, 3, 2]
Expected: [5, 2, 7, 1, 3, 2, 0]