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
  • 7,509
  • 5
  • 26
  • 50
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,567
  • 1
  • 13
  • 23
1

Use lineseparator for this

String separator = System.lineSeparator();

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