ACCU WEATHER

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
  1. Using Additon Operator
  2. Using Multiplicaton Operator
  3. Without using 3rd variable
  4. Using XOR operator
  5. 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);
         }
         
     
    }
}

Popular posts from this blog

Integer Addition

Sum of alternative Numbers

IsEven