Type conversion of int and string, java

前端 未结 5 627
借酒劲吻你
借酒劲吻你 2021-01-02 00:23

last exam we had the exercise to determine the output of the following code:

System.out.println(2 + 3 + \">=\" + 1 + 1);

My answer was <

5条回答
  •  余生分开走
    2021-01-02 00:51

    Assuming that your syntax is :

    System.out.println(2 + 3 + ">=" + 1 + 1);
    

    expressions are evaluated from left to right, in this case 2 + 3 get summed to 5 and when "added" to a string result in "5 >=", which when added to 1 gives "5 >= 1", add another 1 and your result is: "5 >= 11"

提交回复
热议问题