## Java Program:

- To swap 2 numbers without using 3rd variable

#### Example:

User Input
1st number: 3
2nd number: 5

After Swap, Output:
1st number : 5
2nd number : 3

``````import java.util.Scanner;
public class SwapProgram {
public static void main(String []args) {
int n1,n2;
Scanner userInput = new Scanner(System.in);
System.out.print("Enter 1st number : ");
n1 = userInput.nextInt();
System.out.print("Enter 2nd number : ");
n2 = userInput.nextInt();

n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
System.out.println("After Swapping\n Value of 1st number :"+ n1
+ "\n Value of 2nd number : " + n2);
}
}``````

### Output:

```  Enter 1st number : 7
Enter 2nd number : 15
After Swap
1st number : 15
2nd number : 7
```
Program
basic

Here we are adding both values into one then used some maths

``````//Lets take n1=7, n2=3;

n1=n1+n2; //n1=7+3=10
n2=n1-n2; //n2=10-3=7
n1=n1-n2; //n1=10-7=3

//Finally you swaped & get n1=3, n2=7;
``````
Concept

Coming Soon !

Quick
Tutorial

# Quote

Make bold choices and make mistakes. It’s all those things that add up to the person you become.