Java combining two strings -
i'm trying write function combines 2 strings using rules below.
symbols in string taken turns (first string first symbol, second string first symbol, first string second symbol , on) : "jv" + "aa" = "java".
if shorter string reaches end, symbols string added end of string ended : "h" + "ello" = "hello".
this have far:
public static void main(string[] args) { string aa = "jv"; string bb = "aa"; system.out.println(combinestrings(aa, bb)); } public static string combinestrings(string aa, string bb) { string newstring; if(aa.length() > bb.length()){ for(int = 0; < aa.length(); i++){ newstring = aa.substring(i, 1) + bb.substring(i, 1); } } else { } return newstring; }
so initialize
string newstring = "";
Comments
Post a Comment