In the method below, I'm trying to remove values in array input that are less than 0 and greater than 9. I've been doing research and I found that using Arraylist.remove()
would probably be the best way but I am not familiar with that yet. So what I did is try to copy the whole array into a "garbage" array and only put values that are less than 0 and greater than 9. But my output still comes out to be 123145123145-110
?
public static void test (){
int[] input = {1,2,3,1,4,5,1,2,3,1,4,5,-1,10};
int[] garbage = new int[input.length];
for (int i=0; i<input.length; i++){
if (input[i] < 0 && input[i] > 9){
garbage[i] = input[i];
}
int x = input[i];
System.out.print(x);
}
//EDIT
public static void votes(){
int[] input = {1,2,3,1,4,5,1,2,3,1,4,5,-1,10,20};
int count = 0;
int[] garbage = new int[input.length];
for (int i=0; i<input.length; i++){
if (input[i]<0){
garbage[count] = input[i];
i++;
count++;
}
int x = input[i];
System.out.print(x);
}
}