Skip to content

Instantly share code, notes, and snippets.

@dedunumax
Last active February 10, 2024 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dedunumax/c95642c22ed52fdc4cbb to your computer and use it in GitHub Desktop.
Save dedunumax/c95642c22ed52fdc4cbb to your computer and use it in GitHub Desktop.
Swap two integer variables with out a third variable Java
public class SwapInteger{
public static void main(String args[]){
int a = 5;
int b = 10;
System.out.println("Before swapping.");
System.out.println("a = " + a);
System.out.println("b = " + b);
b = a + b;
a = b - a;
b = b - a;
System.out.println("After swapping.");
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment