问题
单项选择题
下面程序的输出为( )。
public class Test
public static void main (String args[])
int x,y;
x=1;
y=2;
System.out.println("The output is"+x+y);
A.The output is xy
B.The output is 3
C.The output is 12
D.The output is x=1 y=2
答案
参考答案:C
解析: Java表达式的同级运算符从左到右进行,括号可以改变优先级。“+”在Java中既是算术的加号,也可以作为字符串的连接符号。“The output is”+x+y中,字符串“The output is”先与x做字符串的连接,结果字符串“The output is 1”再与y做字符串连接。