Swapping with Two Variables Program in Java

Swapping with Two Variables Program in Java
Swapping with Two Variables Program in Java
public class JavaSwapWithTwoVars 
{
    public static void main(String[] args)
	{
        int a=10, b=20;
        System.out.println("Before swapping");
        System.out.println("value of a="+a);
        System.out.println("value of b="+b);
        a=a+b;
        b=a-b;
        a=a-b;
        System.out.println("---------------------------");
        System.out.println("After swapping");
        System.out.println("value of a="+a);
        System.out.println("value of b="+b);
    }
}

Output:

Before swapping
value of a=10
value of b=20
---------------------------
After swapping
value of a=20
value of b=10
b. tech. bca icse java java tutorials learn java mca programs
Recent Posts