[单项选择题] 下列语句能给数组赋值,而不使用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";
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)