输入int和string的转换,java [英] Type conversion of int and string, java

查看:79
本文介绍了输入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"

这篇关于输入int和string的转换,java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆