Looking for a  swap two numbers without using third variable in java ? You are on the correct website. we give you a great collection of java programming We offer How to swap two numbers without using third variable in java. in java and easy to understand.

Java

Example  : How to swap two numbers without using third variable in java.

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int x,y;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter two numbers");
        x = sc.nextInt();
        y = sc.nextInt();

        x = x + y;
        y = x - y;
        x = x - y;

        System.out.println(x);
        System.out.println(y);

    }
}
Java

Output:

Enter Two Numbers : 5  10 
10 
5