[单项选择题] 下面程序的输出结果是( )。 public class Sun {public static void main(String args[ ]){ int[] a=new in

13 查阅

[单项选择题] 下面程序的输出结果是( )。 public class Sun {public static void main(String args[ ]){ int[] a=new int[11]; int[] p=new int[4]; int k=5; for (int i=1; i<=10; i++)a[i]=i; for(int i=1;i<=3;i++)p[i]=a[i*i]; for (int i=1; i<=3;i++)k=k+p [i]*2; System.out.println (k);} }

A.33

B.28

C.35

D.37

参考答案:

A

本题考查对for循环语句和数组的理解。此题中共定义了两个数组,a[]p[]共用了3次for循环。第1个for语句对数组 a[i]赋值,a[1]...a[10]=1...10:第2个for语句,对数组p[i]赋值p[1]=1,p[2]=4,p[3]=9;第3个for语句,计算k的值。3次循环分别得到:5、15、33。故本题答案是A。

计算机考试