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

admin2009-08-24  31

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

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

答案C

解析 A)、D)语法不正确,B)中s[5]的形式只能通过for循环的格式进行赋值,而不能直接赋值。C)中表达式左侧的“[]”说明现在定义一个数组,不需要指明数组长度,而表达式右侧“[]”在后面直接紧跟初始内容时也是不需要指定数组大小的,数组大小直接由初值长度决定。
转载请注明原文地址:https://kaotiyun.com/show/V0np777K
0

最新回复(0)