🍜 Street Food Word Jumble Java Program
Confuse your foodie friends with this fun and tricky Street Food Word Jumble Java challenge! This program mixes two street food names using a creative alternate pattern while preserving the order of vowels. Great for practicing string manipulation in Java!
![]() |
Street Food Word Jumbler In Java |
🧠 Problem Description
You are given two street food names. Your goal is to jumble them into a single string by picking characters alternately from each word, while maintaining the sequence of vowels and characters.
🎯 Rules to Follow
- Pick one character from
str1
and one fromstr2
alternately. - Preserve the order of vowels from both strings.
- If both characters picked are vowels, maintain their relative sequence.
- If one string is exhausted, append the remaining characters from the other string.
- Input may contain uppercase, lowercase, and non-alphabetic characters.
📝 Input
- Two strings
str1
andstr2
(each up to 100 characters).
✅ Output
- A single jumbled string following the alternate character pattern with vowel preservation.
🔡 Sample Input 1
Pizza
Burger
🔠 Sample Output 1
PBiuzrzgaer
🔡 Sample Input 2
Samosa
Chaat
🔠 Sample Output 2
SCamhoaasta
💻 Java Program
import java.util.Scanner;
public class StreetFoodJumble {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input two street food names
System.out.print("Enter the first street food name: ");
String str1 = scanner.nextLine();
System.out.print("Enter the second street food name: ");
String str2 = scanner.nextLine();
// Generate the jumbled word
String jumbledWord = jumbleWords(str1, str2);
System.out.println("Jumbled Output: " + jumbledWord);
scanner.close();
}
private static String jumbleWords(String str1, String str2) {
StringBuilder jumbledWord = new StringBuilder();
int len1 = str1.length(), len2 = str2.length();
int i = 0, j = 0;
// Iterate through both strings
while (i < len1 || j < len2) {
if (i < len1 && isVowel(str1.charAt(i))) {
jumbledWord.append(str1.charAt(i++));
if (j < len2 && isVowel(str2.charAt(j))) {
jumbledWord.append(str2.charAt(j++));
}
} else if (j < len2 && isVowel(str2.charAt(j))) {
jumbledWord.append(str2.charAt(j++));
if (i < len1 && isVowel(str1.charAt(i))) {
jumbledWord.append(str1.charAt(i++));
}
} else {
if (i < len1) jumbledWord.append(str1.charAt(i++));
if (j < len2) jumbledWord.append(str2.charAt(j++));
}
}
return jumbledWord.toString();
}
private static boolean isVowel(char ch) {
return "aeiouAEIOU".indexOf(ch) != -1;
}
}
🔚 Conclusion
This fun Java string manipulation program creatively merges two street food names using logical alternation and vowel preservation. It’s perfect for beginners to practice conditions, loops, and character processing in Java!