Swapping two variable values without using any third variable.

Swapping of two values:

 * @author ashok.kumar
public class Swapping {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int x=2;
		int y=5;
		System.out.format("Value of x=%d and y=%d before swapping.\n",x,y);
		x=x+y;  // x=7
		y=x-y;  // y=2
		x=x-y;  // x=5
		System.out.format("Value of x=%d and y=%d after swapping.",x,y);

Related Links:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

651total visits,1visits today

Leave a Reply

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