printing an int value right after a String value

前端 未结 9 1437
日久生厌
日久生厌 2021-01-27 06:00

I have the following example code:

int pay = 80;
int bonus = 65;
System.out.println(pay + bonus + \" \" + bonus + pay);

could someone please ex

9条回答
  •  一个人的身影
    2021-01-27 06:14

    The 1st pay and bonus in the println returns an integer. So it computes pay+bonus and returns it as an integer before printing it out.

    However, after the "". The + operation then becomes a concatenation of strings and everything after that is returned as a concatenated string. Hence, ("" + bonus + pay) would be returned as "6580".

提交回复
热议问题