您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > JavaSE程序代码阅读题(20180319)
JavaSE程序代码阅读题(20180319)1.阅读下面的代码,然后写出程序运行结果。publicclassTest2{staticbooleanfoo(charc){System.out.print(c);returntrue;)publicstaticvoidmain(String[]argv){inti=0;for(foo(‘A’)jfoo(‘B’)&&(i2);foo(‘C’)){i++;foo(’D’);}}}2.如下程序代码a=0;c=0;do{--c;a=a-1}while(a0);循环结束后,c的值是()3.给出下面的代码:if(x0){System.out.println(first),)elseif(x-3){System.out.println(second);)else{System.out.println(third);)x的取值在什么范围内时将打印字符串”second”4.阅读下面程序,写出其输出:classPerson{Person(){System.out.println(1);}publicvoidprintValue(inti,intj){System.out.println(2);}publicvoidprintValue(inti){System.out.println(3);}}publicclassTeacherextendsPerson{Teacher(){System.out.println(4);}5.下面程序有什么问题,请指正。publicclassPerson{intarr[]=newint[];publicstaticvoidmain(Stringa[]){}}6.写出下列代码的输出结果。publicclassTest{publicintaMethod(){staticinti=0;i++;returni;}publicstaticvoidmain(Stringargs[]){Testtest=newTest();test.aMethod();intj=test.aMethod();System.out.println(j);}}7.下列代码编译运行结果。publicclassDemo{publicintadd(inta,intb){try{returna+b;}catch(Exceptione){System.out.println(“catch语句块”);}finally{System.out.println(“finally语句块”);}return0;}publicstaticvoidmain(String[]args){Demodemo=newDemo();System.out.println(“和是:”+demo.add(9,34));}}8.下列代码编译运行结果。publicstaticvoidmain(String[]args){try{Stringname=null;System.out.println(name.length());}catch(SQLExceptione){System.out.println(“有异常出现”);}finally{System.out.println(“执行结束”);}}9.下列代码编译运行结果。publicclassAnimal{publicAnimal(){System.out.println(“Iamananimal”);}}publicclassCatextendsAnimal{publicCat(){System.out.println(“Iamacat”);}}publicclassTest{publicstaticvoidmain(String[]args){Catcat=newCat();}}10.下列代码编译运行结果。publicclassPerson{privateStringname;publicPerson(){name=“小明”;}publicPerson(Stringname){this();System.out.println(“大家好,我是”+this.name);}publicstaticvoidmain(String[]args){Personperson=newPerson(“小红”);}}11.下列代码编译运行结果。publicstaticvoidmain(String[]args){inti=3;do{if(i--%2==0){System.out.println(i);break;}System.out.println(i);}while(i0);}12.下列代码编译运行结果。publicclassVehicle{publicvoidrun(){System.out.println(“Vehicleisrunning”);}}publicclassCarextendsVehicle{publicvoidrun(){System.out.println(“Carisrunning”);}publicstaticvoidmain(String[]args){Vehiclevehicle=newCar();vehicle.run();}}13.下列代码编译运行结果。doublei=25;intj=5;intresult=i/j;System.out.println(result);14.下列代码编译运行结果。publicclassA{static{Systemoutprintle(“a”)}publicA(){Systemoutprintle(“b”)}}publicclassBextendsA{static{Systemoutprintle(“1”)}publicB(){Systemoutprintle(“2”)}}publicclassTest{publicstaticvoidmain(String[]args){Aab=newB();ab=newB();}}15.下列代码编译运行结果。importjava.util.HashSet;importjava.util.Set;publicclassShortSet{publicstaticvoidmain(String[]ars){SetShorts=newHashSetShort();for(Shorti=0;i100;i++){s.add(i);s.remove(i-1);}System.out.println(s.size());}}16.下列代码编译运行结果。inttotal=0;for(inti=0;i4;i++){if(i==1)continue;if(i==2)break;total+=i;};17.下列代码输入2时的运行结果。publicintgetValue(inti){intresult=0;switch(i){case1:result=result+i;case2:result=result+i*2;case3:result=result+i*3;}returnresult;}18.给出以下代码,请问插入什么语句后可以依次打印输出数组中的每个元素?classExample{publicstaticvoidmain(Stringargs[]){intarr[][]=newint[4][];arr[0]=newint[4];arr[1]=newint[3];arr[2]=newint[2];arr[3]=newint[1];for(intn=0;n4;n++){System.out.println(/*插入语句处*/);}}19.下列代码编译运行结果。publicstaticvoidmain(String[]args){inti=3;do{if(i--%2==0){System.out.println(i);break;}System.out.println(i);}while(i0);}20.下列代码编译运行结果。publicclassTest{publicstaticchangeStr(Stringstr){str=jettech;}publicstaticvoidmain(Stringargs[]){Stringstr=welcome;changeStr(str);System.out.println(str);}}21.下列代码编译运行结果。Stringa=a;Stringb=b;Stringc=a'+b;Stringd=a+b;System.out.print(a==a);System.out.print(c==ab);System.out.print(d==c);System.out.print(newString(a)+b==c);22.下列代码编译运行结果。publicclassSwitchTest{publicstaticvoidmain(String[]args){System.out.println(switchlt(4));}publicstaticintswitchlt(intx){intj=1;switch(x){case1:j++;case2:j++;case3:j++;case4:j++;case5:j++;default:j++;}returnj+x;}}23.下列代码编译运行结果。publicclassHasStatic{privatestaticintx=100;publicstaticvoidmain(String[]args){HasStatichs1=newHasStatic();hs1.x++;HasStatichs2=newHasStatic();hs2.x++;hs1=newHasStatic();hs1.x++;HasStatic.x--;System.err.println(x=+x);}}24.下列代码编译运行结果。publicclassExample{publicstaticvoidmain(String[]args){inti,j;for(i=0,j=0;i+j20;++i,j+=i--){System.out.println(i+j);}}}25.下列代码编译运行结果。publicclassA{publicstaticvoidmain(String[]args){StringA=A;StringB=A;Stringc=newString(A);System.out.print(a==b);System.out.print();System.out.print(a==c);System.out.print();System.out.print(a.equals(c));System.out.print();}}26.下列代码编译运行结果。publicclassA{publicA(){System.out.print(A);}publicstaticvoidmain(Stringargs[]){Aa=newA();Bb=newB();}}classBextendsA{publicB(){System.out.print(B);}}27.下列代码编译运行结果。publicclassA{publicStringmethod1(){try{if(true){thrownewException();}System.out.print(D);returnA}cactch(Exceptione){System.out.print(E);returnB}final{System.out.print(F);}}publicstaticvoidmain(Stringargs[]){System.out.print(newA().method1());}}28.下列代码编译运行结果。publicclassTestTjsinfo{Stringstr=newString(good);char[]ch={'w','e','l','l'
本文标题:JavaSE程序代码阅读题(20180319)
链接地址:https://www.777doc.com/doc-6891927 .html