Created
December 18, 2015 16:28
-
-
Save Yur-ok/b003f0906da4b58667b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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