java - Having trouble with string concatenation -
i trying concatenate string + else, this:
string example = " " (int = 0; < 5; i++) { if (condition ok) { example = example + "\nanother text"; } } joptionpane.showmessagedialog(null, example);
in mind, should've print " (new line)another text" seems work last entry in "another text". like, if condition inside "for" loop ok 3 times, prints " (new line)another text(3)" instead of " (new line) text(1) (new line) text(2)...
any idea of may happening?
edit: after realizing code fine, followed afzalex recommendation , found out error in condition. bro
i used below program got expected output.
string example = " "; (int = 0; < 5; i++) { if (i == 1 || == 3) { example = example + "\nanother text"; } } system.out.println(example);
output:
another text text
so, wrong joptionpane.showmessagedialog(null, example);
if being interpreted html in end, better use </br>
instead of \n
, can give new line.
Comments
Post a Comment