Java pogram to Swapping of two numbers using third variable

Following swapping example program in java for swapping two unique number values with temporary variables. Here is a java program for how swapping happened.

SwappingNumbers.java

public class SwappingNumbers
{
public static void main(String[] args)
   {
	int a=10;
	int b=20;
	int temp;
	temp=a;
	a=b;
	b=temp;
	System.out.println("After Swapping the value of a is : "+a);
	System.out.println("After Swapping the value of b is : "+b);
	
   }
}

Output:

After Swapping value of a is : 20

After Swapping value of b is : 10

Leave a Reply

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