Friday, 24 April 2020

Swapping in Java Program (Interchange)


Write a java program to interchange (swapping) the two values using third variable.  

Solution:
class  interchange
{
    public static void main(String args[])
    {
        int a , b , c ;       
        a = 7 ; b = 15 ;       
        System.out.println("  Before Swapping  ");
        System.out.println("The value of a is " +a);
        System.out.println("The value of b is " +b);       
        c = a ;
        a = b ;
        b = c ;
        System.out.println("\n  After Swapping  ");
        System.out.println("The value of a is " +a);
        System.out.println("The value of b is " +b);
    }
}




No comments:

Post a Comment