JAVA Example to Swap numbers without third Variable
public class SampleSwap {
public static void main(String args[]) {
int x = 10;
int y = 20;
y = (x+y) - (x=y);
System.out.println("X = "+x+"; Y = "+y);
}
}
How it works?
Expressions are executing left to right.
Initially value is
x = 10; y = 20;
So.
y = (x+y) - (x=y);
y = (30) - (x=y);
y = (30) - (20); [Assign x=20; and taking this x value for expression]
y = 10;