笔试Z.docx

上传人:b****2 文档编号:590286 上传时间:2023-04-29 格式:DOCX 页数:33 大小:24.04KB
下载 相关 举报
笔试Z.docx_第1页
第1页 / 共33页
笔试Z.docx_第2页
第2页 / 共33页
笔试Z.docx_第3页
第3页 / 共33页
笔试Z.docx_第4页
第4页 / 共33页
笔试Z.docx_第5页
第5页 / 共33页
笔试Z.docx_第6页
第6页 / 共33页
笔试Z.docx_第7页
第7页 / 共33页
笔试Z.docx_第8页
第8页 / 共33页
笔试Z.docx_第9页
第9页 / 共33页
笔试Z.docx_第10页
第10页 / 共33页
笔试Z.docx_第11页
第11页 / 共33页
笔试Z.docx_第12页
第12页 / 共33页
笔试Z.docx_第13页
第13页 / 共33页
笔试Z.docx_第14页
第14页 / 共33页
笔试Z.docx_第15页
第15页 / 共33页
笔试Z.docx_第16页
第16页 / 共33页
笔试Z.docx_第17页
第17页 / 共33页
笔试Z.docx_第18页
第18页 / 共33页
笔试Z.docx_第19页
第19页 / 共33页
笔试Z.docx_第20页
第20页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

笔试Z.docx

《笔试Z.docx》由会员分享,可在线阅读,更多相关《笔试Z.docx(33页珍藏版)》请在冰点文库上搜索。

笔试Z.docx

笔试Z

1.选择题(3′×10)

 

(1)在java中,100.0*0.6结果等于多少?

d

A、60.0004B、60C、60.00D、60.0

(2)inta='A',请问System.out.println(a)打印出什么?

a

  A、65B、AC、aD、97

(3)System.out.println(Integer.parseInt("+1"))这句话执行会出现什么异常?

a

A、NumberFormatExceptionB、NullPointException

(4)jsp如何获得客户端的IP地址?

a

A、request.getRemoteAddr()

B、Request.ServerVariables("REMOTE_ADDR")

(5)Stringa=newString("foo");

Stringb=newString("foo");

请问System.out.println(a1==b1)打印出什么?

b

A、trueB、falseC、1D、0

(6)Math.round(11.5)的值是多少?

c

A、11B、11.5C、12D、12.0

(7)请问如下哪个方法可以将MenuBar加入Frame中?

b

A、setMenu()

B、setMenuBar()

C、add()

D、addMenuBar()

(8)Whichofthefollowinglinesofcodewillcompilewithouterror?

(多选)bc

A、

inti=0;

if(i){

System.out.println(“Hi”);

}

  B.

   booleanb=true;

   booleanb2=true;

   if(b==b2){

     System.out.println(“Sotrue”);

   }

C.

inti=1;

intj=2;

if(i==1||j==2) System.out.println(“OK”);

D.

inti=1;

intj=2;

if(i==1&|j==2) System.out.println(“OK”);

(9)Jsp路径太深文件名太长就无法读取文件,jsp路径最大长度是多少?

b

A、127B、255C、512D、1024

(10)Considerthefollowingcode:

(多选)CDE

Integers=newInteger(9);

Integert=newInteger(9);

Longu=newLong(9);

Whichtestwouldreturntrue?

A、(s==u)

B、(s==t)

C、(s.equals(t))

D、(s.equals(9))

E、(s.equals(newInteger(9))

2.填空题(4′×5,每题4′)

(1)Strings="Hello";

Strings1=s;

s=s+"world!

";

请问s的值是____HelloWould!

_________,s1的值是___Hello_________。

(2)一个数据库表A(namevarchar(10),ageint),请写出一个SQL语句,按照age排序查出年龄最大的10条记录数___select*top10fromAorderbyageDESC______________________________________。

(3)Stringstr="helloworld!

",请问substring(2,5)的值是__llo_______。

(4)Stringstr="abcdef",inti1=str.lastIndexOf('d',4),inti2=str.lastIndexOf('d',2),请问i1=_____-1_ ;i2=__3__。

(5)hashmap和hashtable区别

_hashmap允许有空值,hashtable不允许,hasptable允许线程同步

______________________________________________________________________

3.改错题(10′×2)

(1)

interfaceA{

inty=0;

}

classB{

intx=1;

}

classCextendsBimplementsA{

publicvoidpX(){

System.out.println(y);

}

publicStringtoString(){

returnthis+"@"+this.hashCode();//去掉this+

}

publicstaticvoidmain(String[]args){

Cc=newC();

c.pX();

System.out.println(c);

}

}

(2)

classTest{

publicstaticvoidmain(String[]args){

HashMaphm=newHashMap();

 Hashtableht=newHashtable();

hm.put("abc",null);

System.out.println(hm.get("abc"));

ht.put("abc",null);

System.out.println(ht.get("abc"));

}}

4.编程题(15′×2)

1(10′)假设有"thank","you","very","much"四个字符串,请编写一个将字符串按照首字母进行排序的程序。

2(10′)字符串的操作:

写一个方法,实现字符串的反转,如:

输入abc,输出cba

答案

1.选择题

1、d

2、A

3、A

4、A

5、B

6、C

7、B

8、B、C

9、B

10、C、E

2.填空题

1、helloworld!

,hello

2、selecttop10*fromAorderbyagedesc

3、llo

4、3,-1

5、hashmap允许空值,而hashtalbe不允许;hashtalbe允许线程同步

3.改错题

1、returnthis+"@"+this.hashCode(); 

此处导致exceptionStackOverflowError,将this+去掉

2、ht.put("abc",null);

此处null不可以,因为hashtable不允许空值,把null换成别的object就可以。

4.编程题

1、publicclassTestsort{

publicvoidsortarray(String[]ar){

Arrays.sort(ar);

}

publicvoidsortvector(Vectorvc){

Collections.sort(vc);

}

publicstaticvoidmain(String[]args){

Testsortts=newTestsort();

Stringar[]={"thank","you","very","much"};

System.out.println("Beforesortarray");

for(inti=0;i

System.out.println(ar[i]);

}

System.out.println("Aftersortarray");

ts.sortarray(ar);

for(inti=0;i

System.out.println(ar[i]);

}

Vectorvc=newVector();

vc.add("thank");

vc.add("you");

vc.add("very");

vc.add("much");

System.out.println("Beforesortvector");

for(Iteratori=vc.iterator();i.hasNext();)

{

System.out.println(i.next().toString());

}

ts.sortvector(vc);

System.out.println("Aftersortvector");

for(Iteratori=vc.iterator();i.hasNext();)

{

System.out.println(i.next().toString());

}

}

}

注:

sortarray和sortvector方法选择其一就可以

2、publicStringreverse(Stringstr){

StringBufferstr1=newStringBuffer(str);

str1.reverse();

returnstr1.toString();

}

或者

publicStringreverse(Stringstr){

Stringstrtemp="";

for(inti=str.length()-1;i>=0;i--){

strtemp+=str.charAt(i)+"";

}

returnstrtemp;

}

面试测试题2

(一)、选择题(4′×10):

(1)Whichofthefollowingrangeofshortiscorrect?

C

A.-27~27-1B.0~216-1C.-215~215-1D.-231~231-1

(2)Whichdeclarationsofidentifiersarelegal?

ABE

A.$personsB.TwoUsersC.*pointD.thisE._endline

(3)Giventhefollowingcode:

C

1:

publicvoidmodify(){

2:

inti,j,k;

3:

i=100;

4:

while(i>0){

5:

j=i*2;

6:

System.out.println("Thevalueofjis"+j);

7:

k=k+1;

8:

i--;

9:

}

10:

}

Whichlinemightcauseanerrorduringcompilation?

C

A.line4B.line6C.line7D.line8

(4)Whichofthefollowingansweriscorrecttoexpressthevalue8inoctalnumber?

A

A.010B.0x10C.08D.0x8

(5)WhicharenotJavakeywords?

AB

A.TRUEB.sizeofC.constD.superE.void

(6)Giventhefollowingcode:

1:

classPerson{

2:

publicvoidprintValue(inti,intj){//...}

3:

publicvoidprintValue(inti){//...}

4:

}

5:

publicclassTeacherextendsPerson{

6:

publicvoidprintValue(){//...}

7:

publicvoidprintValue(inti){//...}

8:

publicstaticvoidmain(Stringargs[]){

9:

Persont=newTeacher();

10:

t.printValue(10);

11:

}

12:

}

Whichmethodwillthestatementonline10call?

D

A.online2B.online3C.online6D.online7

(7)Giventhefollowingcode:

publicvoidtest(){

try{oneMethod();

System.out.println("condition1");

}catch(ArrayIndexOutOfBoundsExceptione){

System.out.println("condition2");

}catch(Exceptione){

System.out.println("condition3");

}finally{

System.out.println("finally");

}

}

WhichwilldisplayifoneMethodrunnormally?

AD

A.condition1B.condition2C.condition3D.finally

(8)Giventhefollowingcode:

publicclassTest{

voidprintValue(intm){

do{System.out.println("Thevalueis"+m);

}

while(--m>10);

}

publicstaticvoidmain(Stringarg[]){

inti=10;

Testt=newTest();

t.printValue(i);

}

}

Whichwillbeoutput?

C

A.Thevalueis8

B.Thevalueis9

C.Thevalueis10

D.Thevalueis11

(9)Giventhefollowingcode:

publicclassPerson{

staticintarr[]=newint[10];

publicstaticvoidmain(Stringa[]){

System.out.println(arr[1];)

}

}

Whichstatementiscorrect?

C

A.Whencompilationsomeerrorwilloccur.

B.Itiscorrectwhencompilationbutwillcauseerrorwhenrunning.

C.Theoutputiszero.

D.Theoutputisnull.

(10)Giventhefollowingcode:

Strings="hello";

Stringt="hello";

charc[]={'h','e','l','l','o'};

Whichreturntrue?

AD

A.s.equals(t);

B.t.equals(c);

C.s==t;

D.t.equals(newString("hello"));

E.t==c.

1、C

2、A、B、E

3、C

4、A

5、A、B

6、D

7、A、D

8、C

9、C

10、A、D

(二)、填空题(4′×5):

(1)、Stringstr=newString(“Practical”);

str+=“Java”;

共产生几个对象:

____5______。

(2)、递归函数sum(inta[],intn)的返回值是数组a[]的前n个元素之和

intsum(inta[],intn)

{if(n>0)return__a[0]+sum(a+1,n-1)________;

  else__return0;

}

(3)、shorts1=1;s1=s1+1和shorts1=1;s1+=1;那个可以编译通过,为什么

_____第二个第一个丢失精度_________________________________________________。

(4)、设intx=1,y=2,z=3,则表达式y+=z--/++x的值是___3_________。

(5)、importjava.util.*;

classInt{

privateinti;

publicInt(intii){i=ii;}

publicvoidincrement(){i++;}

publicStringtoString(){

returnInteger.toString(i);

}

}

publicclasstest{

publicstaticvoidmain(String[]args){

ArrayListv=newArrayList();

for(inti=0;i<10;i++)

v.add(newInt(i));

System.out.println("v:

"+v);

ArrayListv2=(ArrayList)v.clone();

for(Iteratore=v2.iterator();

e.hasNext();)

((Int)e.next()).increment();

System.out.println("v:

"+v);

}

}

上面这段代码输出什么v:

[0,1,2,3,4,5,6,7,8,9]

___v:

[1,2,3,4,5,6,7,8,9,10]______________________________________。

1、5个

2、a[n-1]+sum(a,n-1)或a[0]+sum(a+1,n-1)

return0

3、第二个(第一个丢失精度)

4、3

5、v:

[0,1,2,3,4,5,6,7,8,9]

v:

[1,2,3,4,5,6,7,8,9,10]

(1)、(15′)请编写程序打印下列图案:

*********

*******  

***** 

***

(2)、(25′)Java异常处理机制测试

继承Exception类编写一个自定义异常类MyException,在自定义异常类中加入一个方法getMyMessage(),此方法无参数,返回值为一个字符串,字符串内容为你的自定义异常信息:

"你的姓名:

"+Exception的getMessage()方法的返回值.格式如:

(姓名:

***Exception***)。

编写一个类ExceptionMaker,在里面定义一个方法throwException(),在这个方法中制造一种异常情况,抛出一个JDK自带的异常,捕捉这个异常,并在catch处理语句中抛出你的自定义异常MyException,抛出的自定义异常要求保留原异常的信息(getMessage()的返回值);

再编写一个类MyExceptionTestCase,测试你编写的前面两个类,调用第二个类中的抛出你自定义异常的方法throwException(),捕捉你的自定义异常,并输出你自定义的异常信息.

答案

(三)编程题

1、

publicclassTest01{

publicstaticvoidmain(String[]args){

inti,j,t,c;

j=1;

t=9;

c=5;

while(c>0){

for(i=0;i<=j;i++){

System.out.print("");

}

j++;

for(i=0;i

System.out.print("*");

}

t-=2;

System.out.println();

c--;

}

}

}

2、/**

*自定义的异常类

*/

classMyExceptionextendsException{

privateStringstr;

/**

*抛出异常

*@return抛出异常串

*/

publicStringgetMyMessage(){

returnstr;

}

/**

*构造自定义异常

*@param发生的异常

*/

publicMyException(Exceptione){

Exceptionexcep=newException(e);

str="zhanggenbo"+excep.getMessage();

}

}

/**

*自定义的异常类

*/

classExceptionMaker{

/**

*扑获异常

*/

publicvoidthrowException()throwsArithmeticException,MyException{

try{

inti=3/0;

}catch(ArithmeticExceptione){

System.out.println(e.getMessage());

thrownewMyException(e);

}

}

}

/**

*测试异常类文件

*@author张根波

*/

publicclassMyExceptionTestCase{

/**

*测试异常

*@paramarg入口参数

*/

publicstaticvoidmain(Stringarg[]){

ExceptionMaker

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2