What is output of the following code:
public class Test {
public static void main(String[] args) {
int[] x = {120, 200, 016};
for (int i = 0; i < x.length; i++)
System.out.print(x[i] + " ");
}
}
A.
120 200 16
B.
120 200 14
C.
120 200 20
D.
016 is a compile error. It should be written as 16.
正确答案:B
在该代码中,数组 x 包含三个整数:120、200 和 016。前两个整数是使用十进制表示的,而最后一个整数 "016" 是使用八进制表示,其十进制值为 14。
在循环中,每个数组元素都被打印出来,并在每个元素后面加上一个空格。因此,输出结果是 "120 200 14"。