In my program, I am trying to add values to an array while it is looping. Before it is put in the array, it has to fulfill the if statement. I need to be able to add as many values as needed based on the input. I am not sure how to do this. Any help would be appreciated.
for(int a=0; a<= subset1white.length-1;a++){
String w = Integer.toString(Integer.parseInt(subset1white[a]) + 2);
String x = Integer.toString(Integer.parseInt(subset1white[a]) - 2);
String y = Integer.toString(Integer.parseInt(subset1white[a]) + 10);
String z = Integer.toString(Integer.parseInt(subset1white[a]) - 10);
String[] arithmetic = {w, x, y, z};
for(int b=0; b<= arithmetic.length-1; b++){
if(arithmetic[b] == subset1black[a]){
}
}
}
If the if
loop returns true, I need the subset1black[a]
value to be put in an array called result
. I know how to declare arrays but I do not know how to declare an array where the length can be changed(new values added).