swap two numbers without third variable in java

The below code swap two numbers without third variable in java

import java.io.*;
public class SwapNumbers {

public static void main(String[] args) {

try {
DataInputStream in = new DataInputStream(System.in);
System.out.print(“Enter Number 1 :- “);
int FirstNumber = Integer.parseInt(in.readLine());

System.out.print(“Enter Number 2 :- “);
int SecondNumber = Integer.parseInt(in.readLine());

System.out
.printf(“Values before swaping FirstNumber = %d SecondNumber = %d”,
FirstNumber, SecondNumber);

// swap logic without using third variable
FirstNumber = FirstNumber – SecondNumber;
SecondNumber = FirstNumber + SecondNumber;
FirstNumber = SecondNumber – FirstNumber;

System.out
.printf(“\nValues after swaping FirstNumber = %d SecondNumber = %d”,
FirstNumber, SecondNumber);
} catch (Exception e) {

}
}
}

Output

Enter Number 1 :- 9
Enter Number 2 :- 6
Values before swaping FirstNumber = 9 SecondNumber = 6
Values after swaping FirstNumber = 6 SecondNumber = 9