Swapping two String.

Write a program to input two strings S1 and S2. Swap strings S1 and S2. Print the strings before and after strings before and after interchange.







SOURCE CODE


import java.io.*;

import java.util.*;

public class swaping_string

{

    public static void main(String args[])

    {

        Scanner sc=new Scanner(System.in);

        System.out.print("Enter a String            :");

        String s1=sc.nextLine();

        System.out.print("Enter another String      :");

        String s2=sc.nextLine();

        System.out.println("\n>>>>>>>>>>>>>OutPut<<<<<<<<<<<<<<<<");

        System.out.println("String before swaping");

        System.out.println("S1 = "+s1);

        System.out.println("S2 = "+s2);

        String k=s1;

        s1=s2;

        s2=k;

        System.out.println("String after swaping");

        System.out.println("S1 = "+s1);

        System.out.println("S2 = "+s2);

    }

}


OUTPUT




If you have any question then leave a comment below I will do my best to answer that question.

Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.