My practice problem says to"this method returns an array that has the elements of the specified
// array of Objects, with the Object at the specified index removed.
// the returned array should be smaller by one and have all elements
// in the same relative location to each other. YOU MAY NOT USE
// A LIST :)
Object[] remove(int index, Object[] arr){"
I have come up with this so far, and I'm not entirely sure it works. Can you guys please take a look and give me some feedback on how to fix it so I can do this "remove" properly.
public static remove(int index, Object[] arr){
int counter = 0;
int temp = 2;
int[] arr = {1, 2, 3, 4};
int[] second = new int[arr.length-1];
for(int i=0; i< arr.length;i++){
if(i != temp){
second[counter] = arr[i];
counter ++;
}
//return second;
}
removeneeds a return type. Also, you never use theindexparameter. Other than that, you're really close.indexis the index of the element you want to remove. Looking at your code, you already know how to skip the index that you want to removed. You just called it the wrong thing.