Code Pretty Print Script

Monday, November 18, 2013

Swapping Without Temporary Storage

Can you swap values in place (without temporaries) in Java? Yes!
This classic technique continues to work.
int a = 100;
int b = 200;
a ^= b;
b ^= a;
a ^= b;
System.out.println("A = " + a + ", B = " + b);