Below program will show you how to Swap two numbers without using third variable using java.

public class SwapVariable {

	public static void main(String[] args) {

		// Swaping numbers
		int a = 10;
		int b = 20;
		a = a + b;
		b = a - b;
		a = a - b;

		System.out.println("a: = " + a);
		System.out.println("b: = " + b);

	}

}

 

Output:

Swap two numbers without using third variable

That’s it for Swap two numbers without using third variable

Leave a Reply

Your email address will not be published. Required fields are marked *