Write a function void change() with two string parameters. Interchange/swap the strings and print the strings before and after interchange.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO SWAP THE STRINGS ENTERED:

class t

{

    void change(String s1, String s2)

    {

        String n1 = s1, n2 = s2;

         

        

        System.out.println("The Strings before interchange = ");

        System.out.println("String s1 = "+n1);

        System.out.println("String s2 = "+n2);

        String temp = "";

        temp = n1;

        n1 = n2;

        n2 = temp;

        System.out.println("The Strings after interchange = ");

        System.out.println("The String s1 = "+n1);

        System.out.println("The String s2 = "+n2);

    }

    public static void main (String args[])

    {

        t obj = new t();

        obj.change("HAPPY", "GOODNESS");

    }

}

The above program CODE is compiled and is without any error.

Hope you guys found it helpful.

Please share it with your friends and comment down in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such updates.

Visit us again.

Thank you!!

Comments

Popular Posts