I'm trying to reverse an array, but I don't know how to get the correct output (4,3,2). My questions are; how do I print the output (using System.out.println())? Nothing I've tried works. My second question is; is the rest of my code correct?
public static void main(String[] args) {
int arr[] = {2,3,4};
int i = 0;
int j = arr.length - 1;
while( i < j ) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}