ICSE 2022 SEM-2 QUESTION 7 SOLVED

 /* Define a class to accept two strings of same length and form a new word in such a way that, the first character of the 

 * first word is followed by the first character of the second word and so on.

 * Example - Input: String 1 : BALL

 * String 2 : WORD

 * Output : BWAOLRLD

 */

import java.util.*;

class QUESTION_7

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the first string:");

        String st=sc.nextLine();

        System.out.println("Enter the second string:");

        String str=sc.nextLine();

        String wrd="";

        if(st.length()==str.length())

        {

            for(int i=0;i<st.length();i++)

            {

                wrd=wrd+st.charAt(i)+str.charAt(i);

            }

            System.out.println("Output: "+wrd);

        }

        else

        System.out.println("Both the word should be of same length");

    }

}

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...