《Java编程基础知识点汇总及习题集》--答案

34. 下列哪项不是Java语言的关键字( B )

A.goto B.sizeof C.instanceof D.volatile35. 现有如下五个声明:

Linel:

int

B. 2 C.3 D.编译失败 a_really_really_really_long_variable_name=5 ;

Line2: int _hi=6;

Line3: int big=Integer. getlnteger(\

Line4:int $dollars=8; line5: int %opercent=9; 哪行无法通过编译( D )

A.Line1 B.Line3 C. Line4 D. Line5 36. 现有:

1. class Top { 2. static int x=l;

3. public Top (int y) { x*=3; }

4. }

5. class Middle extends Top { 6. public Middle() {x+=1; } 7. public static void main (String [] args) {

8. Middle m = new Middle(); 9. System. out .println (x);

1O. } 11. }

结果为( D )

37. 现有:

1. class Passer {

2. static final int X=5; 3. public static void

main (String [] args) {

4. new Passer().go (x);

5. System. out .print (x);

6, }

7. void go (int x) { 8. System. out .print(x++);

9. } 10. }

结果是什么( A )

A.55 B.56 C.65

D.66 38. 现有:

1. class Wrench {

2. public static void main(String [] args) {

3. Wrench w=new Wrench(); Wrench w2=new Wrench();

4. w2=go (w, w2); 5. (w2==w); 6. }

7. static Wrench go (Wrench wrl, Wrench wr2) {

8. Wrench wr3=wrl; public static void main (String [] args) {

wrl=wr2; wr2=wr3;

9. return wr3; 10. } 11. }

结果是什么( B )

A. false B.true C.编译失败 D.运行的时候有异常抛出 39. 现有:

1. class Wrench2 { 2. int size;

3. public static void main(String [] args) {

4. Wrench2 w=new Wrench2();

5. =II;

6. Wrench2 w2=go(w, ; 7. System. out .print (w2. size);

8. }

9. static Wrench2 go(Wrench2 wr. int s) {

10. S=12; 11. return wr; 12. } 13. }

结果为( A )

A. 11 B. 12 c.编译失败。 D.运行时异常被抛出 40. 现有:

class Test2 f

short a,b,C; a=l; b=2; C=a+b; a+=2: } }

以上代码中,哪一句是错误的( B )

A.a=1: B.C=a+b; C. a+=2; D. short a,b,C;

41. 表达式:1-2/5+2*5的结果是哪项

( D )

A. B. C. 9 42. 现有代码片段:

String s=\; String sl=S+456;

请问sl的结果是哪项( A ) A. 123456 B. 579 C.编译错误 D.运行时抛出异常

43. 基本数据类型float的包裹类是哪项

( C )

A. Integer B. Double C. Float

D. Character 44. 现有:

1. class Test4 {

2. public static void main

(String [] args) {

3. boolean X=true; 4. boolean y=false; 5. short Z=42;

6. if((z++==42) && (y=true))z++;

7. if((x=false) || …. …. } else { 语句三; 语句四; …. …. (++z==45)) z++;

8. System. (¨z=”+z); 9. } 10. } 结果为( D )

A. Z=42 B. z=44 C. Z= 45 D. z= 46 三、 修改程序错误 1. public class Test{

public static void main(String args[]){

int i; int k=; …. }

课堂笔记

1、 一般if结构 if(布尔类型表达式){ 语句一; 语句二;

}

2、 复杂的if结构

if(布尔类型表达式1){ 语句一; 语句二; …. ….

} else if(布尔类型表达式2){ 语句三; 语句四; …. ….

} else if(布尔类型表达式n){ 语句五; 语句六; …. …. } else{

语句七; …. …. }

3、 Switch条件语句

Switch(表达式){ ….. case 值n:

语句序列n; break; [default:

默认语句序列; break;] }

4、 三元运算符

判断条件表达式1:表达式2

练习题

一、 填空题

1、 假设x为1,给出下列布尔表达式的结果

(1) (x > 0) || (x < 0) ( true ) (2) (x!= 0) ||(x ==0) ( true ) (3) (x >=0)||(x < 0) (true ) (4) (x!=1)==!(x==1) ( true )

2、 写出一个布尔表达式,使得变量a中储存的数据在10到100之间

时,表达值为true。 (a>=10 && a<=100 )

3、已知char x=’a’; char y =’c’; 依次给出下列语句的输出结果。

(1) ( -2 ) (2)

( false )(3)

( true ) (4) == y)

( false )

二、 选择题

1、以下选项中,switch语句判断条件可以接收的数据类型有哪些(多选)( ABCD )

联系客服:779662525#qq.com(#替换为@)