+ 1
How can I concatenated two strings alternatively ?
S1="ab",S2="xy", concatenated="axby" . Just tell me the how to code and the logic explanation also ? I'll be thankful to him/her .âșïž
7 Answers
+ 5
String s3= s1+s2;
or
String s3= s1.concat(s2);
https://www.sololearn.com/learn/Java/2142/
+ 5
Is this ok?
https://code.sololearn.com/c4iX7JcTjmkJ/?ref=app
+ 5
Made a demo code for you
https://code.sololearn.com/c0a0IJ39wyNf/?ref=app
+ 1
In that way I got abxy but I need axby !!
+ 1
it is not about concatenate, but about how divide this strings
String s1="ab", s2="xy";
System.out.println(
""+s1.charAt(0) +s2.charAt(0) +s1.charAt(1) +s2.charAt(1) );
you can use eg s1.substring(0,1) instead
+ 1
StringBuilder builder = new StringBuilder(s1.length() + s2.length());
for(int i = 0; i < s1.length(); i++) {
builder.append(s1.charAt(i));
builder.append(s2.charAt(i));
}
String s3 = builder.toString();
For each valid indexes of your strings, append the characters at this index from both strings, to an accumulator.
0
No sir