This is a description of MixString
public static String mixString(String a, String b) {
String result = "";
int rem = 0;
if (a.length() < b.length()) {
for (int i = 0; i < a.length(); i++) {
result += b.substring(i, i + 1);
result += a.substring(i, i + 1);
rem = i + 1;
}
result += b.substring(rem);
}
else {
for (int i = 0; i < b.length(); i++) {
result += b.substring(i, i + 1);
result += a.substring(i, i + 1);
rem = i + 1;
}
result += a.substring(rem);
}
return result;
}
Function Call | Return Value | |||
---|---|---|---|---|
mixString("abc", "xyz") | → | |||
mixString("Hi", "There") | → | |||
mixString("Hello", "World") | → | |||
mixString("Comp", "Sci") | → | |||
mixString("Big", "oOf") | → | |||
mixString("a", "fntastic") | → |
Experiment with this code on Gitpod.io
Work on a similar problem on CodingBat.com