0

I want my output to be in multiple lines but \n doesn't seem to be working for me. Am I doing something wrong? Thanks

DESIRED OUTPUT

Hello: name

Weight in Kilograms: XX

Height in meters: XX

BMI: XX

CODE

SimpleOutput.showInformation("Hello: " + name \n "Weight in kilograms: " + weightKilograms \n "Height in meters: " + heightMeters \n "BMI: " + (int)bmi);
Wajdy Essam
  • 4,280
  • 3
  • 28
  • 33

3 Answers3

3

You could use String.format

String.format("Hello: %s%n Weight in kilograms: %d%n Height in meters: %d%n  BMI: %d", name, weightKilograms, heightMeters, (int)bmi)

This will also give you a platform independent line separator (as opposed to "\n"), see How do I get a platform-dependent new line character?

Community
  • 1
  • 1
Kulu Limpa
  • 3,501
  • 1
  • 21
  • 31
2

\n is part of string, so include it in your string "XX\n" , also add the string concatenation correclty, like:

SimpleOutput.showInformation("Hello: " + name + "\nWeight in kilograms: " + weightKilograms + "\nHeight in meters: " + heightMeters  + "\nBMI: " + (int)bmi);
Wajdy Essam
  • 4,280
  • 3
  • 28
  • 33
0
SimpleOutput.showInformation("Hello: " + name  + "\nWeight in kilograms: " + weightKilograms  + "\nHeight in meters: " + heightMeters + "\nBMI: " + (int)bmi);
Miki
  • 2,493
  • 2
  • 27
  • 39