简体   繁体   中英

How do I create a new line inside of a concatenated text in java?

So I have made concatenated text in java:

table.setText(num + "*1= " + num);

This is my text, so now if I want to add another string like,: "This is the final answer" but in a new line, how do I do it? NOTE: \n simply doesn't work, as it just shows me an error tha it expects a semicolon.

I tried inserting the escape command \n, however it just said that it expects a semicolon at the end of the escape command, and if I enter a semicolon, It literally crashes the app.

Depending on what you want to do you could use String.format. For instance: String.format("%s *1= %s%nNew line of text", num1, num2); Everything after %n will be printed on a new line. %s will be replaced by the text in num1 and num2 variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM