Java Programming - How do you add text after a number format?

时间:2018-09-18 19:43:44

标签: java printing formatting printf system.out

I have my code working, but I am unable to add text after adding the number format at the end. I keep getting a lot of errors. Is it even possible to add text afterwards? All the examples I have found online are just stopping at the format.

System.out.printf(minutes+" minutes equals "+hour+" hours and equals %.3f %n", day);

Output: 6000 minutes equals 100.0 hours and equals 4.167

I need to add this to the end: 6000 minutes equals 100.0 hours and equals 4.167 days.

1 个答案:

答案 0 :(得分:2)

Just add the text "days" to your string. Additionally, I recommend you don't mix string concatenation and formatting. If you're using string formatting, utilize it for all your variables to make the code easier to read:

System.out.printf
    ("%d minutes equals %d hours and equals %.3f days %n", minutes, hours, day);