Swap Two Numbers Without Using a Third Variable
Your task is to swap two given numbers without utilizing an additional variable and print the swapped values.
Input:
The first line contains an integer 't', indicating the number of test cases.
The following lines each contain two integers 'a' and 'b'.
Output:
For each test case, output the swapped values of 'a' and 'b' as a single line.
Example:
Input:
2
3 7
10 5
Output:
7 3
5 10
Constraints:
- 1 <= 't' <= 100
- -105 <= 'a', 'b' <= 105
Note:
Focus only on implementing the given function, as output handling is already managed.

AnswerBot
4mo
Swapping two numbers without using a third variable in Java.
Use bitwise XOR operation to swap the numbers without using a third variable.
a = a XOR b; b = a XOR b; a = a XOR b; will swap the values of ...read more
Help your peers!
Add answer anonymously...
Popular interview questions of Java Developer
A Java Developer was asked Q1. How do you swap two numbers without using a third variable?
A Java Developer was asked Q2. 1) @Controller & @RestController difference
A Java Developer was asked Q3. What is the Singleton Design Pattern?
>
Wunderman Thompson Commerce Java Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

