一、选择题
1 . 定义一个数组String [ ] cities={ “北京”,”上海”,”天津”,”重庆”,”武汉”,”广州”,”香港”},数组中的cities[6]指的是(C)。
A.北京 B.广州
C.香港 D.数组越界
2. 下列数组的初始化正确的是(BD)。(选择两项)
A.int score={90,12,34,77,56};//数据类型 数组名=new数据类型[数组长度 ];
B.int[ ] score=new int[5];//int数组未赋值,默认5个0,String数组默认null
C.int[ ] score=new int[5]{90,12,34,77,56};//二者选其一
D.int score[ ]=new int[ ]{90,12,34,77,56};
3. 以下代码的输出结果是(A)。
public class Test{
public static void main(String[] args){
double[] price=new double[5];
price[0]=98.10;
price[1]=32.18;
price[2]=77.74;
for (int i=0;i<5;i++){
System.out.print((int)price[i]+” ”)
}//double进行强制转换为int,丢失精度
}//price[3]、price[4]未赋值,默认为0
}
A . 98 32 77 0 0
B . 98 32 78 0 0
C . 98 32 78
D .编译出错
4. 阅读下面代码,它完成的功能是(B)。
String[ ]a ={ “我们”,”你好”,”小河边”,”我们”,”读书”};
for (int i=0; i<a.length;i++){
If(a[i].equals("我们")){ //查找
a[i]=”他们”;//替换
}
}
-
查找 B.查找并替代 C.增加 D.删除
5. 下面代码的运行结果是(C)。
Public class Test {
Public static void main(String[] args){
int[ ] a=new int[3];
int[ ] b=new int[ ]{1,2,3,4,5};
a=b;//把b数组的地址赋给a数组的地址 a整个存储结构就发生改变,与b数组一致
for ( int i=0; i<b.length;i++){
System.out.print(a[i]+” ”)
}
}
}
A . 程序报错 B. 1 2 3
C. 1 2 3 4 5 D. 0 0 0
二、简答题
1. 阅读以下代码,找出其中的错误。
String[ ] scores= new String[5]{ “mike”,”Lily”,”Sunny”