问题 单项选择题

下列程序执行后,k的值是( )。  public class Testddd{  public static void main(String args[ ])  {    inti;10,j=18 K=30;    switch(j-i)    { case 8:k++;     case 9:k+ =2;     case 10:k+ =3;     default:k/=j;    }   System.out.println(k);    }  }

A.31

B.32

C.2

D.33

答案

参考答案:C

解析:仔细观察case后的语句,每个都没有用break关键字;在switch语句中,是通过break关键字来退出switch语句的。而在题目中,case 8:k++;后没有break,则继续执行k+=2;这时还没有break语句,继续执行,这时的k的值是33;一直执行完k+=3;这时k的值是36;default语句是当表达式的值与任一case子句中的值都不匹配时,程序执行default后面的语句。在题目中,因为在执行完case 10:k+=3;后还没有break,所以要执行k=k/j得k的值是2。break语句是用来退出循环,并从紧跟该循环语句的第―条语句处开始执行;而continue语句则是跳过循环体中下面尚未执行的语句,回到循环体的开始处继续下一轮的循环。

阅读理解

Is it difficult for you to get up in the morning ?  Hiroyuki’s bed will solve your problem ! Here is how it works .

The bed is connected to an alarm clock . First , the alarm clock rings . You have a few minutes to wake up . Next , a tape recorder in the bed plays soft music . The tape recorder in Hiroyuki’s bed plays a recording of his girlfriend . She whispered in a soft voice , “Wake up , darling , please .”  After minutes later , Hiroyuki hears a recording of his boss . His boss shouts , “Wake up at once , or you’ll be late !”

If you don’t get up after the second recording , a mechanical “foot” in the bed will kick you in the head . The bed waits a few more minutes . What ! You’re still in bed ! Slowly the top of the bed rises higher and higher . The foot of the bed goes lower and lower . Finally you slide off the bed and onto the floor . You are out of bed awake !

Hiroyuki’s bed is not in stores . There is only one bed--- the bed Hiroyuki made for a contest(竞赛). Maybe someday a company will make Hiroyuki’s bed and sell it in stores . Maybe people will buy millions of beds . Then Hiroyuki will be rich . If the bed makes Hiroyuki rich , he won’t need to work , and he won’t need to get up early !

(   ) 4. The bed is useful to the people _______ .

A. who can’t sleep well      B. who can’t get up early

C. who go to bed early       D. who go to bed late

(   ) 5. The bed is not connected to _______ .

A. an alarm clock           B. a tape recorder

C. a TV                   D. a mechanical “foot”

(   ) 6. What will finally happen to Hiroyuki if he doesn’t get up ?

A. He will slide onto the floor .

B. A tape recorder will play a recording of his boss .

C. A mechanical “foot” will kick him in the head .

D. The bed will rise higher and higher

单项选择题