Returns a Reversed Version of an Array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(reversed(lst)));
}
static int[] lst = {1, 2, 3, 4, 5};
static int[] reversed(int[] x){
int size = x.length;
int[] xcopy = new int[size];
int counter = size - 1;
int revcount = 0;
while (counter >= 0) {
xcopy[revcount] = x[counter];
counter -= 1;
revcount ++;
}
return xcopy;
}
}