简体   繁体   中英

\n doesn't work? What's wrong in my code?

I don't get the new line using the code below.
Can anyone tell me how to fix this?

String sum="";
int input = Integer.parseInt(value.getText().toString());
for (int i = 0; i < 10; i++) {
    sum += i + input;
    display.setText(sum+"\n");
}

This is how it should work:

String sum="";
int input = Integer.parseInt(value.getText().toString());
for (int i = 0; i < 10; i++)
{
    sum += i + input + "\n";
}
display.setText(sum);

Add the \\n inside the loop.
Then display the whole string after the loop has completed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM