流程控制异常和断言有关断言的题不用做Word格式.docx
- 文档编号:19247346
- 上传时间:2023-01-04
- 格式:DOCX
- 页数:15
- 大小:371.29KB
流程控制异常和断言有关断言的题不用做Word格式.docx
《流程控制异常和断言有关断言的题不用做Word格式.docx》由会员分享,可在线阅读,更多相关《流程控制异常和断言有关断言的题不用做Word格式.docx(15页珍藏版)》请在冰豆网上搜索。
2.给出下面的代码:
7.casex:
9.casex-2:
(1)
C.210100
D.212012
E.在第8行编译失败。
F.在第9行编译失败。
3.给出下面的代码:
1.publicclassIf1{
2.staticbooleanb;
3.publicstaticvoidmain(String[]args){
4.shorthand=42;
5.if(hand<
50&
!
b)hand++;
6.if(hand>
50);
7.elseif(hand>
40){
8.hand+=7;
9.hand++;
}
10.else
11.--hand;
12.System.out.println(hand);
14.}
哪一项是运行结果
A.41
B.42
C.50
D.51
E.在第5行编译失败。
F.在第6行编译失败。
4.Giventhefollowing,
4;
8.default:
def"
9.casex-1:
break;
10.casex-2:
whatistheresult?
A.0def1
B.210def1
C.210defdef
D.21def0def1
E.2120def12
F.210def1def1
5.给出以下代码:
1.publicclassIf2{
2.staticbooleanb1,b2;
4.intx=0;
5.if(!
b1){
6.if(!
b2){
7.b1=true;
8.x++;
9.if(5>
6){
10.x++;
12.if(!
b1)x=x+10;
13.elseif(b2=true)x=x+100;
14.elseif(b1|b2)x=x+1000;
15.}
16.}
17.System.out.println(x);
18.}
19.}
A.0
B.1
C.101
D.111
E.1001
F.1101
◆流程控制(循环)
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行和第5行有一个语法错误。
D.在第4行有一个语法错误。
E.在第4行和第5行有一个语法错误。
F.在第5行有一个语法错误。
7.给出下面的代码:
1.classFor{
2.publicvoidtest(){
3.
4.System.out.println("
x="
+x);
5.}
andthefollowingoutput,
x=0
x=1
哪两行语句独立地插入到第3行能够产生输出?
A.for(intx=-1;
x<
2;
++x){
B.for(intx=1;
++x){
C.for(intx=0;
x>
D.for(intx=0;
x++){
E.for(intx=0;
8.给出以下代码:
1.publicclassTest{
2.publicstaticvoidmain(String[]args){
3.intI=1;
4.dowhile(I<
1)
Iis"
+I);
6.while(I>
1);
A.Iis1
B.Iis1Iis1
C.没有输出。
D.编译错误。
E.Iis1Iis1Iis1inaninfiniteloop.
9.给出下面的代码:
11.intI=0;
12.outer:
13.while(true){
14.I++;
15.inner:
16.for(intj=0;
j<
10;
j++){
17.I+=j;
18.if(j==3)
19.continueinner;
20.breakouter;
21.}
22.continueouter;
23.}
24.System.out.println(I);
25.
26.
(1)
A.1
B.2
C.3
D.4
10.给出下面的代码:
1.intI=0;
2.label:
3.if(I<
2){
4.System.out.print("
5.I++;
6.continuelabel;
哪一项是运行的结果?
A.Iis0
B.Iis0Iis1
C.编译错误。
D.以上都不对。
◆异常
11.给出下面的代码:
1.System.out.print("
Start"
2.try{
3.System.out.print("
Helloworld"
4.thrownewFileNotFoundException();
5.try{
6.out=newFileOutputStream("
test.txt"
7.out.write(122);
9.catch(IOExceptionio){
10.System.out.println("
IOError."
12.finally{
13.out.close();
下面哪一项是正确的?
A.程序将成功编译。
B.第4行有一个错误。
C.第6行有一个错误。
D.第9行有一个错误。
E.第13行有一个错误。
14.给出下面的代码:
1.publicclassMyProgram{
2.publicstaticvoidthrowit(){
3.thrownewRuntimeException();
4.}
5.publicstaticvoidmain(Stringargs[]){
6.try{
7.System.out.println("
Helloworld"
8.throwit();
9.System.out.println("
Donewithtryblock"
11.finally{
12.System.out.println("
Finallyexecuting"
A.程序不能编译。
B.程序将输出:
Helloworld,然后将输出:
aRuntimeExceptionhas
occurred,然后将输出:
Donewithtryblock,最后将输出:
Finallyexecuting。
C.程序将输出:
occurred,最后将输出:
D.程序将输出:
Finallyexecuting,最后将输出:
aRuntimeExceptionhasoccurred。
15.给出下面的代码:
1.publicclassRTExcept{
2.publicstaticvoidthrowit(){
throwit"
4.thrownewRuntimeException();
6.publicstaticvoidmain(String[]args){
7.try{
8.System.out.print("
hello"
9.throwit();
11.catch(Exceptionre){
12.System.out.print("
caught"
14.finally{
15.System.out.print("
finally"
17.System.out.println("
after"
A.hellothrowitcaught
B.编译失败。
C.hellothrowitRuntimeExceptioncaughtafter
D.hellothrowitRuntimeException
E.hellothrowitcaughtfinallyafter
F.hellothrowitcaughtfinallyafterRuntimeException
◆断言
16.下面哪一项是正确的?
A.在一个断言语句中,冒号(:
)后面可以跟任何Java表达式。
B.如果一个switch块没有default,添加一条语句是恰当的。
C.在一个断言语句中,如果在冒号后面没有表达式,断言的错误信息将是空的。
D.使用catch子句处理处理断言失败是恰当的。
17.下面哪两项是正确的?
A.显式地抛出一个断言错误有时是一个好的做法。
B.在你认为不可能执行到的地方放一个断言是一个好的做法。
C.私有的getter()和setter()不应当使用断言去验证参数。
D.如果在一个try-catch块中产生了一个断言错误,finally块将被跳过。
E.使用catch块处理断言错误是正确的。
18.给出以下代码:
2.publicstaticinty;
3.publicstaticvoidfoo(intx){
foo"
5.y=x;
7.publicstaticintbar(intz){
bar"
9.returny=z;
11.publicstaticvoidmain(String[]args){
12.intt=0;
13.assertt>
0:
bar(7);
14.assertt>
1:
foo(8);
15.System.out.println("
done"
17.}
A.bar
B.bardone
C.foodone
D.barfoodone
E.编译失败。
19.下面哪两项是正确的?
A.包含断言语句的程序在运行时不加参数,缺省情况下断言语句将被执行。
B.在Java1.4版本中,缺省情况下断言语句能够被编译。
C.正确地使用运行时参数,可以指示虚拟机关闭某一个类中的断言同时打开某一个包中的断言。
D.下面都是合法的运行时断言标志:
-ea,-esa,-dsa,-enableassertions,-disablesystemassertions
E.虚拟机在处理命令行参数时,对–ea标志的处理会优先于–da标志。
20.给出下面的代码:
1.publicclassTest2{
2.publicstaticintx;
3.publicstaticintfoo(inty){
4.returny*2;
7.intz=5;
8.assertz>
0;
9.assertz>
2:
foo(z);
10.if(z<
7)
11.assertz>
12.switch(z){
13.case4:
System.out.println("
4"
14.case5:
5"
15.default:
assertz<
17.if(z<
10)
18.assertz>
4:
z++;
19.System.out.println(z);
20.}
哪一行是不恰当地使用了断言的例子?
A.第8行。
B.第9行。
C.第11行。
D.第15行。
E.第18行。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 流程 控制 异常 断言 有关 不用