Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java reverse array

public void reverseArray(int[] arr) {
	int len = arr.length;
    int left = 0, right = len - 1 - left;
    while (left < right) {
        swap(arr, left, right);
        left++;
        right--;
    }
}
    
private void swap(int[] arr, int left, int right) {
    int tmp = =arr[left];
    arr[left] = arr[right];
    arr[right] = tmp;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #reverse #array
ADD COMMENT
Topic
Name
6+4 =