+ 2
Java code
Anyone know why my this code print [, , , , , , , , , , , , , , , , , ,] https://code.sololearn.com/ctgE332b8V81/?ref=app
4 Respuestas
+ 4
Because ans2 returns a string, but you add nothing to s, therefore it stays as an empty string, and that will be added to the arraylist. I think you wanted to do s += x + " ";
instead of System.out.println(x, " ");
+ 3
The string returned by the call to ans2 is empty, and it is added to the arraylist. The string representation of an arraylist contains elements printed one after the other inside square brackets seperated by commas. Since the elements are empty, you get and arraylist of empty strings separated by commas.
+ 1
Wang Teng Zheng I don't know the expected output, so maybe you can try what Airree suggested and see if that works out for you.
If you wish to achieve something else, kindly provide an explanation regarding the same.
0
Kinshuk Vasisht did u know anywhere instead of arraylist to return the ans