Last active
February 10, 2024 04:26
-
-
Save dedunumax/c95642c22ed52fdc4cbb to your computer and use it in GitHub Desktop.
Swap two integer variables with out a third variable Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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