I need to reverse an array for example move what ever is in spot 5 to 0, 4 to1, 3 to 2.
int size, length;
System.out.print("how big of a list do you have: ");
size=reader.nextInt();
length=size-1;
int [] array = new int [size];
for (int count=0; count < array.length; count ++){
System.out.println("enter a number: ");
array [count] = reader.nextInt();
}
for (int count=length; count > 0; count --)
array [(length-count)];
}
}
I am doing this in eclipse and I keep getting an error in the last line saying that I am not using an operator/expression : array [(length-count)]; but I dont know why the minus sign is not working? or if my program will work in general it did not get past the build part.
tempis used so that numbers don’t overwrite each other. Think of it like getting food from a fridge. The milk is behind the water, and you want some milk. In order to get the milk, you take the water and put it in your hand (tempwould be the hand). You then put the milk where the water was and the water where the milk was. Without the “hand”, you would have lost your water (fallen on the floor, or in the case oftemp, lost in memory) and only be left with milk.