0

In my project, I and taking four strings from text fields and putting them together in a different text field using the setText in Java. I need them to be in four different lines, but right now there are all in a line with no spaces between them

How do I break the line between the different strings.

I tried using the \n, but I just got an error.

Here is the line of code I am using

display.setText(manu+brand+year+price);

which gives me this output

fordfocus20003500.0

I want

ford
focus
2000
3500.0
Aidan Gomez
  • 8,167
  • 5
  • 28
  • 51
ndpasu
  • 39
  • 3

2 Answers2

1

The \n needs to be quoted because it's not a variable, it's a character:

display.setText(manu+"\n"+brand+"\n"+year+"\n"+price);

Having said that, I'm not sure what kind of object display is, it might not support new lines? What is display?

Matt
  • 3,677
  • 1
  • 14
  • 24
1

Use lineseparator for this

String separator = System.lineSeparator();

display.setText(manu + separator + brand + separator + year + separator + price);
Krishna Chandran
  • 389
  • 3
  • 18