写出下面程序的输出()。public class Test {public static void main (String args[ ]) {iht x=1,

题目

写出下面程序的输出( )。 public class Test { public static void main (String args[ ]) { iht x=1, y=2; System. out. println ("result="+x+y); System. out. println ("result="+(x+y));

A.result=12 result=12

B.result=3 result=3

C.result=3 result=12

D.result=12 result=3

参考答案和解析
正确答案:D
解析:Java表达式的同级运算符从左到右进行,括号可以改变优先级。+在Java中既是算术的加号也可以作为字符串的连接符号。"result="+x+y中,字符串"result="先与x做字符串的连接,结果字符串result=1再与y做字符串连接。在"result"+(x+y)中,先计算括号中的加法运算,结果为3,"result="再与3做字符串连接。
更多“写出下面程序的输出()。public class Test {public static void main (String args[ ]) {iht x=1, ”相关问题