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
Related Articles
Deepen your understanding with these curated continuations.
JAVA 5 min read
How to Find ASCII Value of a Character in Java: 4 Easy Methods
Master finding ASCII values in Java! Explore 4 different methods including type-casting, brute force, and byte arrays with clear, practical code examples.
Vishnu
Program 5 min read
Factorial of a Number Using For Loop in Java: Code & Algorithm
Find the factorial of any integer in Java using a for loop. Explore the step-by-step logic, code implementation, and why we initialize the result variable to 1.
Vishnu
Program 5 min read
Factorial of a Number Using While Loop in Java: Guide & Code
Learn how to calculate the factorial of a number in Java using a while loop. This guide includes a step-by-step algorithm, code examples, and output analysis.
Vishnu