Swap two variables without a third variable

The code snippet to swap two variables a & b without a third variable,


private static void swap(int a, int b) {
  a = a + b;
  b = a - b;
  a = a - b;

  System.out.println("a: "+a+" b: "+b);
}




Shortcut for System.out.println in intelliJ is cntrl+SPACE

Comments

Popular posts from this blog

AlarmManager and Notification in Android

Open Gallery and get the selected image in appplication

Dismiss or Cancel dialog by swipe gesture