发布时间 : 星期五 文章java习题解答更新完毕开始阅读71ab28dd680203d8ce2f24a5
D.String s=\你好\
E. String s=null; int i=(s!=null)&&(s.length()>0)?s.length():0; 15.下列代表十六进制整数的是( C )。
A.012345 B.2008 C.0xfa08 D.fb05 16.在switch(expression)语句中,expression的数据型不能是( C )。 A.char B.short C.double D.byte 17.下列说法正确的是( AC )。
A.表达式“1+2>3”的值是false B.表达式“1+2||3”是非法的表达式 C.表达式“i+j=1”是非法的表达式 D.表达式“1+2>3”的值是true
18.指出正确的表达式( B )。
A.byte=128; B.long l=0xfffL; C.Boolean=null; D.double=0.9239d;
19.public class T18 {
static int arr[] = new int[10];
public static void main(String a[]) { System.out.println(arr[1]); } }
哪个语句是正确的?( C )
A.编译时将产生错误 B.编译时正确,运行时将产生错误 C.输出零 D.输出空
20.若String s = \e','l','l','o'} ; 则下列哪些表达式返回true?( AB )
A.s.equals(t); B.t.equals(new String(\C.t.equals(c); D.s==t; 21.执行下面的代码段:
switch(m){ case 0: System.out.println(\
case 1: System.out.println(\ case 2:
default: System.out.println(\
}
下列m的哪些值将引起\的输出?( CD ) A.0 B.1 C.2 D.3
22.下列关于“<<”和“>>”的运算,哪些是正确的?( AC ) A.0000 0100 0000 0000 0000 0000 0000 0000<<5 的运行结果是
1000 0000 0000 0000 0000 0000 0000 0000
B.0000 0100 0000 0000 0000 0000 0000 0000<<5的运行结果是
1111 1100 0000 0000 0000 0000 0000 0000
C.1100 0000 0000 0000 0000 0000 0000 0000>>5的运行结果是
1111 1110 0000 0000 0000 0000 0000 0000
D.1100 0000 0000 0000 0000 0000 0000 0000>>5的运行结果是
0000 0110 0000 0000 0000 0000 0000 0000 三、判断题
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=\( × )
13.说明或声明数组时不分配内存大小,创建数组时分配内存大小。( √ )
14.强制类型转换运算符的功能是将一个表达式的类型转换为所指定的类型。( √ ) 四、分析题
1.分析下面的程序,写出运行结果。 public class Exercises5_1 {
String str = new String(\ char[] ch = { 'L', 'i', 'k', 'e' };
public static void main(String args[]) { Exercises5_1 ex = new Exercises5_1(); ex.change(ex.str, ex.ch); System.out.print(ex.str + \ System.out.print(ex.ch); }
public void change(String str, char ch[]) { str = \ ch[1] = 'u'; } }
运行结果是:( Hi ! Luke )
2.分析下面的程序,写出运行结果。 public class Exercises5_2 {
public static void main(String[] args) { int n = 1, m, j, i; for (i = 3; i <= 30; i += 2) { m = (int) Math.sqrt((double) i);
for (j = 2; j <= m; j++) if ((i % j) == 0) break; if (j >= m + 1) { System.out.print(i + \ if (n % 5 == 0) System.out.print(\ n++; } } } }
运行结果是:( )
3 5 7 11 13 17 19 23 29
3.分析下面的程序,写出运行结果: public class Exercises5_3 { public static void main(String args[]) { String str1 = new String(); String str2 = new String(\ char chars[] = { 'a', ' ', 's', 't', 'r', 'i', 'n', 'g' }; String str3 = new String(chars); String str4 = new String(chars, 2, 6); byte bytes[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }; String str5 = new String(bytes); StringBuffer strb = new StringBuffer(str3); System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ }
}
运行结果是:( )
The String str1 is
The String str2 is String 2 The String str3 is a string The String str4 is string The String str5 is 0123456789 The String strb is a string
五、改错题
1.找出下面代码的错误部分,说明错误类型及原因,并更正。
public int m1 (int number[20]){ number = new int[20]; for(int i=0;i 改正后程序: public int[] m1(int number[]) { // number = new int[20]; for (int i = 1; i < number.length - 1; i++) } number[i] = number[i - 1] + number[i + 1]; return number; 2.找出下面代码的错误部分,说明错误类型及原因,并更正。 (1) int x = 1; while (x <= 10); { i++; } 改正后程序: int x = 1, i = 0; while (x <= 10) { i++; } (2) switch (n) { case 1: system.out.println(\ case 2: system.out.println(\ break; } 改正后程序: int n = 1; switch (n) { case 1: System.out.println(\); break; System.out.println(\); break; case 2: