Java printing a string containing multiple integers

后端 未结 7 1721
别那么骄傲
别那么骄傲 2021-01-19 08:16

Just starting learning java today and can\'t seem to figure this out. I am following the tutorial on learnjavaonline.org which teaches you a few things and then asks you to

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 08:29

    An easy and ugly way to do this would be to use String.valueOf for each numerical value.

    As in:

    String output = h + String.valueOf(three); // + etc...
    

    Edit

    morgano's approach is perfectly valid as well - +1 for that.

    On a more general topic, you might want to use String.concat for String concatenation, or even better, a StringBuilder object.

    This SO page contains a lot of info you can use on the matter.

提交回复
热议问题