Created
March 15, 2013 15:53
-
-
Save charlespunk/5170880 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
Write a function to swap a number in place (that is, without temporary variables). |
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 void swap(int a, int b){ | |
a = a - b; | |
b = a + b; | |
a = b - a; | |
System.out.println("a is " + a); | |
System.out.println("b is " + b); | |
} | |
public static void swap(int a, int b){ | |
a = a ^ b; | |
b = a ^ b; | |
a = a ^ b; | |
System.out.println("a is " + a); | |
System.out.println("b is " + b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment