输入int和string的转换,java

输入int和string的转换,java

问题描述:

上次考试我们进行了练习以确定以下代码的输出:

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

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

我的答案是 5> = 2 但现在我意识到这是错误的答案。它应该是 5> = 11
但是为什么?

My answer was 5 >= 2 but now I realize that this is the wrong answer. It should be 5 >= 11. But why?

假设你的语法是:

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

表达式从左到右进行评估,在这种情况下,2 + 3总和为5,当添加到字符串结果5> =,当添加到1时会给出5> = 1,再添加1,结果为:5> = 11

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"