java - return strings with concatination with the use of for loop -
i'm trying return value of ?,?,? when executing main function. however, ?, answer. don't want use system.out.println (although job) because want return values function. first return works want in second part, not sure how concatenate 2 returns , loop because useless after i've change println return
public static void main(string[] args) { scanner kb = new scanner(system.in); r r = new r(); system.out.println(r.func(3)); } public static string func(int size) { if(size == 1) return "?"; else { (int = 1; < size; i++) { return "?,"; } return "?"; } }
editted code little bit, trying use return statements within loop. have understand once return statement called, specified value automatically taken out of function. cannot use multiple versions of this. try code below , see if works. ive made string, , added "?," each time needs to.
public static void main(string[] args) { scanner kb = new scanner(system.in); r r = new r(); system.out.println(r.func(3)); } public static string func(int size) { string value = ""; if(size == 1) return "?"; else { (int = 1; < size; i++){ value += "?,"; } value+= "?"; return value; }
}
Comments
Post a Comment