作业2
一、选择题
1.下面哪些标识符在Java语言中是合法的?( AB )
A.persons$ B.TwoUsers C.instanceof D.end-line 2.若x = 5,y = 8,则表达式x|y的值为( B )。 A.3 B.13 C.0 D.5
3.若定义有short s; byte b; char c; 则表达式s * b + c的类型为( C ) A.char B.short C.int D.byte 4.下列循环语句的循环次数是( B )。 int i=5;
do { System.out.println(i--); i--;
}while(i!=0);
A.5 B.无限 C.0 D.1 5.下列关于数组的定义形式,正确的是?( D )
A.int[ ]c=new char[10]; B.int[ ][3]=new int[2][ ]; C.int[ ]a; a=new int; D.char b[ ]; b=new char[80]; 6.在switch(expression)语句中,expression的数据型不能是( C )。 A.char B.short C.double D.byte 7.下列说法正确的是( AC )。
A.表达式“1+2>3”的值是false B.表达式“1+2||3”是非法的表达式 C.表达式“i+j=1”是非法的表达式 D.表达式“1+2>3”的值是true 8.public class T {
static int arr[] = new int[10];
public static void main(String a[]) { System.out.println(arr[1]);
}
}
哪个语句是正确的?( C )
A.编译时将产生错误 B.编译时正确,运行时将产生错误 C.输出零 D.输出空
9.若String s = \{'h','e','l','l','o'} ; 则下列哪些表达式返回false?( C ) A.s.equals(t); B.t.equals(new String(\C.t.equals(c); D.s==t; 二、判断题
1.Java语言使用的是Unicode字符集,每个字符在内存中占8位。( × ) 2.Java中不同数据类型的长度是固定的,不随机器硬件不同而改变。(√ ) 3.所有的变量在使用前都必须进行初始化。( × )
4.已知byte i = (byte)127; i = i +1;这两个语句能被成功编译。( √ ) 5.String str=\char chr=str.charAt(9); (× ) 6.char[] chrArray={ 'a', 'b', 'c', 'd', 'e', 'f', 'g'};
char chr=chrArray[6]; ( √ )
7.int i,j; boolean booleanValue=(i==j); ( × ) 8.int intArray[]={0,2,4,6,8};
int length=int Array.length();( × )
9.String str=\( × ) 10.short shortValue=220; byte byteValue=shortValue; ( × ) 11.int[] intArray[60]; ( × ) 12.char[] str=\( × )
相关推荐: