Advertisement
sci4me

XOR Swap

Jun 12th, 2015
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1. int x = 42;
  2. int y = 24;
  3.  
  4. System.out.println("x: " + x + "\ny: " + y);
  5.  
  6. x = x ^ y;
  7. y = x ^ y;
  8. x = x ^ y;
  9.  
  10. System.out.println("x: " + x + "\ny: " + y);
  11.  
  12. //
  13.  
  14. int x = 42;
  15. int y = 24;
  16.  
  17. System.out.println("x: " + x + "\ny: " + y);
  18.  
  19. x = x + y;
  20. y = x - y;
  21. x = x - y;
  22.  
  23. System.out.println("x: " + x + "\ny: " + y);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement