Mahfuz Ahmed likhon
Mahfuz Ahmed likhon

Reputation: 109

\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");
}

Upvotes: 0

Views: 197

Answers (1)

Phant&#244;maxx
Phant&#244;maxx

Reputation: 38098

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.

Upvotes: 1

Related Questions