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);
3
  • 2
    What programming language is this? Commented Sep 19, 2014 at 23:13
  • the language is Java Commented Sep 19, 2014 at 23:15
  • 2
    \n is part of string, so include it in your string "XX\n" Commented Sep 19, 2014 at 23:15

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

Comments

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);

1 Comment

You didn't spell "correclty" correclty.
0
SimpleOutput.showInformation("Hello: " + name  + "\nWeight in kilograms: " + weightKilograms  + "\nHeight in meters: " + heightMeters + "\nBMI: " + (int)bmi);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.