Without using arraylists, arraycopy, or any other imported method, but simply just using for loops and an additional array, how does one remove the first occurrence of a certain element?
this is my code so far:
public class remover {
public static void main(String[] args) {
//initial array
int[] oldArray = {1,2,3,4};
//value to remove is 3
//define the new array with smaller size
int[] newArray = new int[oldArray.length];
//cycle through array
for(int i=0;i < oldArray.length;i++)
{
if(oldArray[i] == 3) {
for(int k=0; k<i; k++) {
newArray[i] = oldArray[i];
}
for(int m=i; m<oldArray.length; m++) {
newArray[m] = oldArray[m];
}
}
}
for(int i=0; i<oldArray.length; i++) {
System.out.println(oldArray[i]);
}
}
}