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);

1 comment :

  1. Such a nice blog shared by you. Get the Document Storage Facility from safestorage.in perfect storage solution to protect your documents. For the more details you can visit on Document Storage Facility

    ReplyDelete