Below Example shows how to swap two variables without using third variable. The Simple logic behind swapping is to add and subtract both values in given variables.
public class SwapTwoNumbersWithoutThirdVariable {
public static void main(String[] args) {
int a = 12;
int b = 6;
System.out.println("BEFORE SWAP : A = "+a+" ,B = "+b);
a = a+b;
b = a-b;
a = a-b;
System.out.println("AFTER SWAP : A = "+a+" ,B = "+b);
}
}
Program Output:
BEFORE SWAP : A = 12 ,B = 6
AFTER SWAP : A = 6 ,B = 12
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial

Useful Information!!!...Thank You
ReplyDeleteaviation institute in chennai
air hostess academy in chennai
Airport Management Training in Chennai
airport ground staff training courses in chennai
medical coding in chennai
top 10 fashion designing colleges in chennai
interior design courses in chennai part time