Skip to content

Instantly share code, notes, and snippets.

@Yur-ok
Created December 18, 2015 16:28
Show Gist options
  • Save Yur-ok/b003f0906da4b58667b9 to your computer and use it in GitHub Desktop.
Save Yur-ok/b003f0906da4b58667b9 to your computer and use it in GitHub Desktop.
package Lesson3.KeyPoint2;
import java.util.Arrays;
/**
* Created by Юрий on 18.12.2015.
*/
public class VoidSwap {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7};
int[] arr1 = new int [0];
System.out.println(Arrays.toString(arr));
swap(arr);
System.out.println(Arrays.toString(arr));
swap(arr1);
System.out.println(Arrays.toString(arr1));
}
static void swap(int[] data) {
if (data == null || data.length == 0) {
System.out.println(-1);
return;
}
int temp;
for (int i = 0, k = 1; (i < data.length - 1 && k <= data.length - 1); i++, k++) {
temp = data[i];
data[i] = data[k];
data[k] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment