Swapping four number:

Why we use swapping four numbers:

Swapping is used to variables to refresh to mutual exchanging the values of the variables. Generaly, this is done with the data in memory. The simplest method to swap four variables using without fifth temporary variables.

Example:

public class Swappingfour
{
public static void main(String[] args)
{
	int no1= 10;
	int no2= 20;
	int no3 = 30;
	int no4=40;
	 no1=no3-no1;
	 no4=no4-no3;
	 no3=no1+no2;
	 no2=no4+no1;
	 {
		 System.out.println(no1);
		 System.out.println(no2);
		 System.out.println(no3);
		 System.out.println(no4);
	 }
}
}

output:

Leave a Comment