I wanted to have a method that makes an array and a method that changes the array (the 13 into a 6 and add 2 on the fourth item) and then catch both the changed and unchanged arrays in variables, but I can't seem to call the changed array in the main, without there being an error
public class ArrayFillApp {
public static void main(String[] args) {
ArrayFill arrayFill = new ArrayFill();
arrayFill.makeArray();
for(int value: arrayFill.makeArray()){
System.out.println(value);
}
}
}
public class ArrayFill {
public int[] makeArray(){
int[] array = {
6, 13, 34, -10, 15
};
return array;
}
public int[] changeArray(int[] array){
array[1] = 6;
array[3] = array[3] + 2;
int[] arrayCopy = new int[array.length];
for (int value: array) {
array[value] = arrayCopy[value];
}
return arrayCopy;
}
}
arrayFill.makeArray();this line should've been used to capture the array returned by themakeArraymethod. You completely ignored the returned array. Error #2: You never calledchangeArraymethod. When you do, make sure you don't ignore the returned array like you did withmakeArray.