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:
That’s it for Swap two numbers without using third variable