MeshWorld India LogoMeshWorld.
JAVAProgram1 min read

Program to mixup characters of 2 strings in JAVA

Vishnu
By Vishnu
Program to mixup characters of 2 strings in JAVA

In this article we’ll see a program to mixup characters of 2 string in JAVA.

Input

Consider a two strings as Good and Day.

Code

public class StringMixup
{
  public static void main(String[] args)
  {
    String str1 = "Good", str2 = "Day";
    int i = 0, str1Length = str1.length(), str2Length = str2.length();
    String output = "";

    while(i < str1Length || i < str2Length)
    {
      output += i < str1Length ? str1.charAt(i) : "";
      output += i < str2Length ? str2.charAt(i) : "";
      i++;
    }

    System.out.println("String1: " + str1);
    System.out.println("String2: " + str2);
    System.out.println("Output: " + output);
  }
}

Output

String1: Good
String2: Day
Output: GDoaoyd

Happy 😄 coding

Share_This Twitter / X
Vishnu
Written By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Enjoyed this article?

Support MeshWorld and help us create more technical content