You are here: Home / Topics / Swaping of Variables using third Variable in Java

Swaping of Variables using third Variable in Java

Filed under: Java on 2023-08-11 19:16:00

// Swapping example using third variable

class  Swap
{
public static void main( String args[ ] )
{
 int  a, b, t;

 a = 10;
 b = 20; 

 System.out.print( "\nBefore Swapping :" );
 System.out.print( a + "   " + b );

 t = a;
 a = b;
 b = t;
 
 System.out.print( "\nAfter Swapping  : " );
 System.out.print( a + "   " + b );
}
}


Output:

Before Swapping :  10 20

After Swapping  : 20 10

About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.