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

admin2010-07-28  24

问题 下面程序的输出结果是(    )。    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;            for(int i=1;i<=3;i++)                p=a[i*i];            for (int i=1; i<=3;i++)                k=k+p *2;            System.out.println (k);       }    }

选项 A、33
B、28
C、35
D、37

答案1

解析 本题考查对for循环语句和数组的理解。此题中共定义了两个数组,a[]p[]共用了3次for循环。第1个for语句对数组 a赋值,a[1]...a[10]=1...10:第2个for语句,对数组p赋值p[1]=1,p[2]=4,p[3]=9;第3个for语句,计算k的值。3次循环分别得到:5、15、33。故本题答案是A。
转载请注明原文地址:https://kaotiyun.com/show/u29p777K
0

最新回复(0)