class ReverseArrayElements1
{
public static void main ( String[] args )
{
int[] values = {10, 20, 30, 40};
int temp;
System.out.println( "Original Array: " + values[0] + "\n" + values[1] +
"\n" + values[2] + "\n" + values[3] );
// reverse the order of the numbers in the array
System.out.println( "Reversed Array: " + values[0] + "\n" + values[1] + "\n"
+ values[2] + "\n" + values[3] );
}
}
Task I need to complete the program so that the numbers in the array appear in reversed order. This does not mean that I can just need to display the elements in reverse order; I will actually move the last element in the array into the the first element of the array, and so on. I can't use a loop or create a new array.
The output should be
Original Array: 10 20 30 40
Reversed Array: 40 30 20 10
temp = arr[0]; arr[0]= arr[3]; arr[3]=tmp;to swap border values, and thentemp = arr[1]; arr[1]=arr[2]; arr[2]=tmp;to swap middle values.