Created
September 1, 2015 17:37
-
-
Save jweinst1/16a80f39e1d367ce5148 to your computer and use it in GitHub Desktop.
Swaps two items in an array in Java
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
| import java.util.Arrays; | |
| class Main { | |
| public static void main(String[] args) { | |
| System.out.println(Arrays.toString(swapitem(lst, 3, 1))); | |
| } | |
| static int[] lst = {2, 3, 1, 5, 6, 7}; | |
| static int[] swapitem(int[] x, int y, int z) { | |
| int temp = x[y]; | |
| x[y] = x[z]; | |
| x[z] = temp; | |
| return x; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment