Swap the integers
Given two Integer numbers A and B. Swap the values of A nad B.
*Hint: Try to solve them using different logics. There is 8 Possible ways to implement this 1. Using 3rd variable
- Using Additon Operator
- Using Multiplicaton Operator
- Without using 3rd variable
- Using XOR operator
- Using single statement and Many more .....
Input Format
First line contains No of test cases T
Next followed T lines each line contains two space seperated values.
Constraints
1<= T <= 100
1<= A, B <= 9000
Output Format
Print the values of A & B after applying swapping.
Sample Input 0
5
1 2
3 5
10 34
23 43
100 1
Sample Output 0
2 1
5 3
34 10
43 23
1 100
Sample Input 1
1
99 1987
Sample Output 1
1987 99
Source Code:
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner ik=new Scanner(System.in);
int n=ik.nextInt();
for(int i=0;i<=n;i++)
{
int a=ik.nextInt();
int b=ik.nextInt();
a = a + b;
b = a - b;
a = a - b;
System.out.println(a+" "+b);
}
}
}