Skip to content

Instantly share code, notes, and snippets.

@johnroper100
Created January 28, 2019 18:50
Show Gist options
  • Save johnroper100/a9c068db2d49302719a07dd86d89c2b3 to your computer and use it in GitHub Desktop.
Save johnroper100/a9c068db2d49302719a07dd86d89c2b3 to your computer and use it in GitHub Desktop.
Swap two 2D array items in Java
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