Created
June 5, 2025 08:29
-
-
Save asdf913/dce24d35cfb609e1aaac77d0bb1cca0b to your computer and use it in GitHub Desktop.
Swap Value From Two Variables Without Temporary Variable
This file contains hidden or 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 SwapValueFromTwoVariablesWithoutTemporaryVariable { | |
public static void main(final String[] args) { | |
// | |
int a = 10; | |
// | |
int b = 2; | |
// | |
System.out.println("a=" + a + ",b=" + b); | |
// | |
a = a + b; | |
// | |
System.out.println("a=" + a + ",b=" + b); | |
// | |
b = a - b; | |
// | |
System.out.println("a=" + a + ",b=" + b); | |
// | |
a = a - b; | |
// | |
System.out.println("a= " + a + ",b=" + b); | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output