Home ICSE Computer Applications Class 10 – Previous Year Question Papers & Solutions / Programs / 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 – BALLInput string 2 – WORD OUTPUT : BWAOLRLD
🚀 Programming Example

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
Input string 2 – WORD

OUTPUT : BWAOLRLD

👁 81 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.
No previous program
No next program

📌 Information & Algorithm

Given Input:


Expected Output:


💻 Program Code

import java.util.Scanner;

public class RansariStringMerge
{
    public static void main(String args[]) 
    {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter String 1: ");
        String s1 = in.nextLine();
        System.out.println("Enter String 2: ");
        String s2 = in.nextLine();
        String str = "";
        int len = s1.length();
        
        if(s2.length() == len)
        { 
            for (int i = 0; i < len; i++) 
            {
                char ch1 = s1.charAt(i);
                char ch2 = s2.charAt(i);
                str = str + ch1 + ch2;
            }
            System.out.println(str);
        }
        else
        {
             System.out.println("Strings should be of same length");
        }
    }
}
                        
No previous program
No next program
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.