-流程控制、异常和断言-有关断言的题不用做.doc

-流程控制、异常和断言-有关断言的题不用做.doc

ID:57845731

大小:353.50 KB

页数:12页

时间:2020-09-02

-流程控制、异常和断言-有关断言的题不用做.doc_第1页
-流程控制、异常和断言-有关断言的题不用做.doc_第2页
-流程控制、异常和断言-有关断言的题不用做.doc_第3页
-流程控制、异常和断言-有关断言的题不用做.doc_第4页
-流程控制、异常和断言-有关断言的题不用做.doc_第5页
资源描述:

《-流程控制、异常和断言-有关断言的题不用做.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、内容概要练习u流程控制(if和switch)1.给出以下代码:1.publicclassSwitch2{2.finalstaticshortx=2;3.publicstaticinty=0;4.publicstaticvoidmain(String[]args){5.for(intz=0;z<3;z++){6.switch(z){7.casey:System.out.print("0");8.casex-1:System.out.print("1");9.casex:System.out.print("2

2、");10.}11.}12.}13.}哪一项是运行结果?A.012B.012122C.在第7行编译失败。D.在第8行编译失败。E.在第9行编译失败。F.运行时抛出异常。2.给出下面的代码:1.publicclassSwitch2{2.finalstaticshortx=2;3.publicstaticinty=0;4.publicstaticvoidmain(String[]args){5.for(intz=0;z<3;z++){6.switch(z){7.casex:System.out.print("

3、0");8.casex-1:System.out.print("1");9.casex-2:System.out.print("2");10.}11.}12.}13.}哪一项是运行结果?(1)A.012B.012122C.210100D.212012E.在第8行编译失败。F.在第9行编译失败。3.给出下面的代码:1.publicclassIf1{2.staticbooleanb;3.publicstaticvoidmain(String[]args){4.shorthand=42;5.if(hand<50

4、&!b)hand++;6.if(hand>50);7.elseif(hand>40){8.hand+=7;9.hand++;}10.else11.--hand;12.System.out.println(hand);13.}14.}哪一项是运行结果A.41B.42C.50D.51E.在第5行编译失败。F.在第6行编译失败。4.Giventhefollowing,1.publicclassSwitch2{2.finalstaticshortx=2;3.publicstaticinty=0;4.publics

5、taticvoidmain(String[]args){5.for(intz=0;z<4;z++){6.switch(z){7.casex:System.out.print("0");8.default:System.out.print("def");9.casex-1:System.out.print("1");break;10.casex-2:System.out.print("2");11.}12.}13.}14.}whatistheresult?A.0def1B.210def1C.210defde

6、fD.21def0def1E.2120def12F.210def1def15.给出以下代码:1.publicclassIf2{2.staticbooleanb1,b2;3.publicstaticvoidmain(String[]args){4.intx=0;5.if(!b1){6.if(!b2){7.b1=true;8.x++;9.if(5>6){10.x++;11.}12.if(!b1)x=x+10;13.elseif(b2=true)x=x+100;14.elseif(b1

7、b2)x=x+1000;

8、15.}16.}17.System.out.println(x);18.}19.}哪一项是运行结果?A.0B.1C.101D.111E.1001F.1101u流程控制(循环)6.给出下面的代码:1.publicclassWhile{2.publicvoidloop(){3.intx=0;4.while(1){5.System.out.print("xplusoneis"+(x+1));6.}7.}8.}哪一项是正确的?A.在第1行有一个语法错误。B.在第1行和第4行有一个语法错误。C.在第1行、第4行和第

9、5行有一个语法错误。D.在第4行有一个语法错误。E.在第4行和第5行有一个语法错误。F.在第5行有一个语法错误。7.给出下面的代码:1.classFor{2.publicvoidtest(){3.4.System.out.println("x="+x);5.}6.}7.}andthefollowingoutput,x=0x=1哪两行语句独立地插入到第3行能够产生输出?A.for(intx=-1;x<2;++x){B.for(i

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。