So I want to Push a new item onto the end of the array (the numbers 1-9). I was told by a friend that the code I have written is correct, but when I run it on eclipse, nothing happens. What do I need to do? Should I just print the array under the main block? thanks.
public static void main(String[] args) {
long[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
}
public static long[] push(long[] array, long item) {
// Add one item to an array
long cellsToAdd = 1;
long[] array2 = new long[array.length + 1];
// copy each item in array2 -> array3
for (int i = 0; i < array.length; i++) {
array[i] = array2[i];
}
array2[array2.length - 1] = item;
System.out.println("Array: ");
// Print the array to the console
for (long p : array2) {
System.out.println(p);
}
return array2;
}