Husnain Sheraz Husnain Sheraz - 2 months ago 16
Java Question

How to print a string which is a variable between text that isn't a variable in java?

So I want to print multiple variables between a string.

For example, say you are answering a questionnaire and all the answers are being saved as strings.

And you want to finish off by saying from answering this questionnaire I learned that you (insert question one answer here) and that your favourite colour is (insert question 2 answer here).

String userInformation = ("Firstly thank you for taking the questionare and secondly this is what I have learnt about you from taking that quesionare:The date you took this questionare was on " + questionOne ". And that you also live in the country: " + questionTwo ". that your gender is: " + questionThree ". And you are " + questionFour " years of age. When asked if you can code you said " + questionFive ". When asked how often you listend to music your replied " + questionSix ". Your favorite colour is " + questionSeven ". Your favorite food is " + questionEight ". And the time you took the questionare was " + questionNine ". And lastly when asked did you enjoy this questionare you replied " + questionTen ".");

Answer Source

You need to add + after the variables too.

String userInformation = ("Firstly thank you for taking the questionare and secondly this is what I have learnt about you from taking that quesionare:The date you took this questionare was on  " 
+ questionOne + 
". And that you also live in the country: " 
+ questionTwo + 
". that your gender is: "  
+ questionThree + 
". And you are "  
+ questionFour + 
" years of age. When asked if you can code you said " 
+ questionFive + 
". When asked how often you listend to music your replied " 
+ questionSix + 
". Your favorite colour is " 
+ questionSeven + 
". Your favorite food is " 
+ questionEight + 
". And the time you took the questionare was " 
+ questionNine + 
". And lastly when asked did you enjoy this questionare you replied "
+ questionTen + 
".");