Skip to content

Instantly share code, notes, and snippets.

@mmathys
Created October 20, 2020 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmathys/1e1f064892dcae89bdecc797b3b97550 to your computer and use it in GitHub Desktop.
Save mmathys/1e1f064892dcae89bdecc797b3b97550 to your computer and use it in GitHub Desktop.
Swap Arrays
import java.util.Arrays;
class Main {
public static void main(String[] args) {
int[] array = new int[2];
array[0] = 1;
array[1] = 2;
System.out.println("Vorher: " + Arrays.toString(array));
/* Swap */
int temp = array[0];
array[0] = array[1];
array[1] = temp;
System.out.println("Nachher: " + Arrays.toString(array));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment