下列语句能给数组赋值,而不使用for循环的是

admin2012-03-21  44

问题 下列语句能给数组赋值,而不使用for循环的是

选项 A、myArray{[1]="One";[2]="Two";[3]="Three";}
B、String s[5]=new String[] {"Zero","One","Two","Three","Four"};
C、String s[]=new String[] {"Zero","One","Two","Three","Four"};
D、String s[]=new String[]= {"Zero","One","Two","Three","Four"};

答案C

解析 字符串数组赋初值的方法有两种,一种是如选项C一样初始化。另外一种是先为每个数组元素分配引用空间,再为每个数组元素分配空间并赋初值。例如还可做如下赋值:
   string s[]=new String[5];
   s[0]="Zero";
   s[1]="One";
   s[2]="Two";
   s[3]="Three";
   s[4]="Four";
转载请注明原文地址:https://kaotiyun.com/show/L62p777K
0

最新回复(0)