-
-
Save johnroper100/a9c068db2d49302719a07dd86d89c2b3 to your computer and use it in GitHub Desktop.
Swap two 2D array items 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
public static int[][] swap(int[][] array, int firstRow, int firstCol, int lastRow, int lastCol) { | |
int first = array[firstRow][firstCol]; | |
int last = array[lastRow][lastCol]; | |
array[firstRow][firstCol] = last; | |
array[lastRow][lastCol] = first; | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment