swapAlternates

mail@pastecode.io avatar
unknown
java
2 years ago
189 B
1
Indexable
Never
public void swapAlternates(int arr[]) {
    for(int i = 0; i < arr.length - 1; i++) {
        int temp = arr[i];
        arr[i] = arr[i + 1];
        arr[i + 1] = temp;
        i++;
    }
}