java复习题答案.docx

上传人:b****6 文档编号:5861571 上传时间:2023-01-01 格式:DOCX 页数:21 大小:20.86KB
下载 相关 举报
java复习题答案.docx_第1页
第1页 / 共21页
java复习题答案.docx_第2页
第2页 / 共21页
java复习题答案.docx_第3页
第3页 / 共21页
java复习题答案.docx_第4页
第4页 / 共21页
java复习题答案.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

java复习题答案.docx

《java复习题答案.docx》由会员分享,可在线阅读,更多相关《java复习题答案.docx(21页珍藏版)》请在冰豆网上搜索。

java复习题答案.docx

java复习题答案

复习题1

一、选择题答案

选择第1题

B

选择第2题

A

选择第3题

C

选择第4题

B

选择第5题

A

选择第6题

A

选择第7题

B

选择第8题

C

选择第9题

B

选择第10题

B

选择第11题

C 

二、多项选择题答案

多项选择第1题

BD

多项选择第2题

AE

多项选择第3题

AC

多项选择第4题

AE

多项选择第5题

AE

多项选择第6题

DEF

多项选择第7题

AC

多项选择第8题

BC

多项选择第9题

AB

多项选择第10题

CD

多项选择第11题

CD

多项选择第12题

ACD

多项选择第13题

ABD 

三、填空题答案

填空第1题

x=10,a=3,b=4,c=5

填空第2题

java.util

填空第3题

(public)(static)(void)(main)(Stringargs[])

填空第4题

1

填空第5题

26 

四、编程题答案

1

 publicclassHelloWorld

  { 

  publicstaticvoidmain(Stringargs[])

  {

   System.out.println("Hello,World!

");

  }

 }

 importjava.awt.Graphics;

 importjava.applet.Applet;

 publicclassHelloWorldextendsApplet{

  Strings;

 publicvoidinit(){

  s="HelloWorld!

";

 }

 publicvoidpaint(Graphicsg){

  g.drawString(s,25,25);

 }

}

2

 classyanghui

 {

 publicstaticvoidmain(Stringargs[])

 {

  inti,j;

  intyhlevel=10;

  intyanghui[][];

  System.out.println("杨晖三角形:

");

  yanghui=newint[yhlevel][];

  for(i=0;i

   yanghui[i]=newint[i+1];

   yanghui[0][0]=1;

  for(i=1;i

  {

  yanghui[i][0]=1;

  for(j=1;j

   yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];

   yanghui[i][yanghui[i].length-1]=1;

  }

  for(i=0;i

  {

   for(j=0;j

   System.out.print(yanghui[i][j]+"");

   System.out.println();

   }

  }

 }

输出结果是:

杨晖三角形:

1

11

121

1331

14641

15101051

1615201561

172135352171

18285670562881

193684126126843691

3

 importjava.io.*;

 publicclassMemoController{

  FileOutputStreamfos;

  OutputStreamWriterosw;

  BufferedWriterbw;

 publicMemoController(){

  try{

    fos=newFileOutputStream("memo.txt",true);

    osw=newOutputStreamWriter(fos);

    bw=newBufferedWriter(osw);

    }catch(FileNotFoundExceptione){};

  }

 publicsynchronizedvoidappend(Strings){

  try{

    bw.write(s,0,s.length());

    bw.flush();

    bw.close();

    osw.close();

    fos.close();

    }catch(IOExceptione){}

  }

 publicstaticvoidmain(Stringargs[]){

  MemoControllermmc=newMemoController();

  mmc.append("Iamxubin");

  }

 }

4

 importjava.io.*;

 classPhones

 {

  staticFileOutputStreamfos;

  publicstaticfinalintlineLength=81;

  publicstaticvoidmain(Stringargs[])throwsIOException

  {

   byte[]phone=newbyte[lineLength];

   byte[]name=newbyte[lineLength];

   intI;

   try

   {

    fos=newFileOutputStream("phone.numbers");

  }

   catch(FileNotFoundExceptione)

   {}

   while(true)

   {

    System.err.println("Enteraname(enter'done'toquit)");

    readLine(name);

    if("done".equalsIgnoreCase(newString(name,0,0,4)))

    {

     break;

    }

    System.err.println("Enterthephonenumber");

    readLine(phone);

    for(inti=0;phone[i]!

=0;i++)

   {

    fos.write(phone[i]);

   }

    fos.write(',');

    for(inti=0;name[i]!

=0;i++)

   {

    fos.write(name[i]);

   }

    fos.write('\n');

   }

    fos.close();

   }

   privatestaticvoidreadLine(byteline[])throwsIOException

  {

   inti=0,b=0;

   while((i

='\n'))

   {

    line[i++]=(byte)b;

   }

    line[i]=(byte)0;

   }

  }

复习题2

四、编程题答案

1

 publicclassHelloWorld

  { 

  publicstaticvoidmain(Stringargs[])

  {

   System.out.println("Hello,World!

");

  }

 }

 importjava.awt.Graphics;

 importjava.applet.Applet;

 publicclassHelloWorldextendsApplet{

  Strings;

 publicvoidinit(){

  s="HelloWorld!

";

 }

 publicvoidpaint(Graphicsg){

  g.drawString(s,25,25);

 }

}

2

 classyanghui

 {

 publicstaticvoidmain(Stringargs[])

 {

  inti,j;

  intyhlevel=10;

  intyanghui[][];

  System.out.println("杨晖三角形:

");

  yanghui=newint[yhlevel][];

  for(i=0;i

   yanghui[i]=newint[i+1];

   yanghui[0][0]=1;

  for(i=1;i

  {

  yanghui[i][0]=1;

  for(j=1;j

   yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];

   yanghui[i][yanghui[i].length-1]=1;

  }

  for(i=0;i

  {

   for(j=0;j

   System.out.print(yanghui[i][j]+"");

   System.out.println();

   }

  }

 }

输出结果是:

杨晖三角形:

1

11

121

1331

14641

15101051

1615201561

172135352171

18285670562881

193684126126843691

3

 importjava.io.*;

 publicclassMemoController{

  FileOutputStreamfos;

  OutputStreamWriterosw;

  BufferedWriterbw;

 publicMemoController(){

  try{

    fos=newFileOutputStream("memo.txt",true);

    osw=newOutputStreamWriter(fos);

    bw=newBufferedWriter(osw);

    }catch(FileNotFoundExceptione){};

  }

 publicsynchronizedvoidappend(Strings){

  try{

    bw.write(s,0,s.length());

    bw.flush();

    bw.close();

    osw.close();

    fos.close();

    }catch(IOExceptione){}

  }

 publicstaticvoidmain(Stringargs[]){

  MemoControllermmc=newMemoController();

  mmc.append("Iamxubin");

  }

 }

4

 importjava.io.*;

 classPhones

 {

  staticFileOutputStreamfos;

  publicstaticfinalintlineLength=81;

  publicstaticvoidmain(Stringargs[])throwsIOException

  {

   byte[]phone=newbyte[lineLength];

   byte[]name=newbyte[lineLength];

   intI;

   try

   {

    fos=newFileOutputStream("phone.numbers");

  }

   catch(FileNotFoundExceptione)

   {}

   while(true)

   {

    System.err.println("Enteraname(enter'done'toquit)");

    readLine(name);

    if("done".equalsIgnoreCase(newString(name,0,0,4)))

    {

     break;

    }

    System.err.println("Enterthephonenumber");

    readLine(phone);

    for(inti=0;phone[i]!

=0;i++)

   {

    fos.write(phone[i]);

   }

    fos.write(',');

    for(inti=0;name[i]!

=0;i++)

   {

    fos.write(name[i]);

   }

    fos.write('\n');

   }

    fos.close();

   }

   privatestaticvoidreadLine(byteline[])throwsIOException

  {

   inti=0,b=0;

   while((i

='\n'))

   {

    line[i++]=(byte)b;

   }

    line[i]=(byte)0;

   }

  }

 二、多项选择题答案

多项选择第1题

ACD

多项选择第2题

AB

多项选择第3题

AD

多项选择第4题

CD

多项选择第5题

AD

多项选择第6题

AC

多项选择第7题

AD

多项选择第8题

BC

多项选择第9题

BD

多项选择第10题

BCD

多项选择第11题

BD

多项选择第12题

ABD

多项选择第13题

BD

多项选择第14题

ABD 

三、填空题答案

填空第1题

Collection,List,Map,Set

填空第2题

7

填空第3题

因为在A的main方法中,还没有A的实例就要试图生成内部类的实例 

四、编程题答案

编程第1题

  importjava.io.*;

  publicclassPoint

  {

   intx,y;

  publicPoint(intx,inty)

  {

   this.x=x;

   this.y=y;

  }

  publicPointgetPoint()

  {

   PointtempPoint=newPoint(x,y);

   returntempPoint;

   }

   publicvoidsetPoint(Pointpoint)

   {

    this.x=point.x;

    this.y=point.y;

   }

   publicstaticvoidmain(Stringargs[])

   {

    PointPoint1=newPoint(3,4);

    System.out.println("Point1:

"+"("+Point1.x+","+Point1.y+")");

    PointPoint2=Point1.getPoint();

    System.out.println("Point2:

"+"("+Point2.x+","+Point2.y+")");

    PointPoint3=newPoint(5,6);

    Point1.setPoint(Point3);

    System.out.println("Point1:

"+"("+Point1.x+","+Point1.y+")");

   } 

  }

编程第2题

  importjava.io.*;

  classFileCopy

  {

   publicstaticvoidmain(String[]args)

   {

    FileInputStreamin;

    FileOutputStreamout;

    if(args.length<2)

   {

    System.out.println("Usage:

javacopysrcfiledestfile");

    System.exit(-1);

   }

   try

   {

    in=newFileInputStream(args[0]);

    out=newFileOutputStream(args[1]);

    copyFile(in,out);

   }

   catch(Exceptione)

   {

    System.out.println(e);

   }

  }

   privatestaticvoidcopyFile(FileInputStreamin,FileOutputStreamout)

   {

    intlength;

    bytebuf[]=newbyte[1024];

  

    try{

      while((length=in.read(buf,0,1024))!

=-1)

    {

     out.write(buf,0,length);

    }

   }

   catch(Exceptione)

   {

    System.out.println("Error:

"+e);

    System.exit(-1);

   }

  }

 }

编程第3题

  importjava.awt.*;

  importjava.awt.event.*;

  importjava.applet.*;

  importjava.util.*;

publicclassTimeViewerextendsAppletimplementsActionListener,Runnable{

   Threadtimer;

   TextFieldin,out;

   Buttonbb;

   Panelp1,p2,p3;

   booleanstate;

   publicvoidinit(){

    in=newTextField(20);

    out=newTextField(20);

    bb=newButton("CurrentTime:

");

    p1=newPanel();

    p2=newPanel();

    p3=newPanel();

    setLayout(newGridLayout(3,1));

    setSize(200,100);

    p1.add(in);

    p2.add(bb);

    p3.add(out);

    add(p1);

    add(p2);

    add(p3);

    bb.addActionListener(this);

    timer=newThread(this);

    state=true;

    timer.start();

   }

   publicvoidactionPerformed(ActionEvente){

    //out.setText(in.getText());

    out.setText(currentTime());

   }

   publicvoidrun(){

    while(true){

    try{

       timer.sleep(1000);

    }catch(InterruptedExceptione){}

    in.setText(currentTime());;

    }

  }

  StringcurrentTime(){

   Datenow=newDate();

   Stringstr=now.getHours()+":

"+now.getMinutes()+":

"+now.getSeconds();

   returnstr;

  }

 }

复习题3

一、选择题答案

选择第1题

C

选择第2题

D

选择第3题

D

选择第4题

C

选择第5题

B

选择第6题

B

选择第7题

C

选择第8题

D

选择第9题

A

选择第10题

A

选择第11题

B

选择第12题

B 

二、多项选择题答案

多项选择第1题

AB

多项选择第2题

BD

多项选择第3题

ADE

多项选择第4题

AD

多项选择第5题

BCD

多项选择第6题

AB

多项选择第7题

ABCD

多项选择第8题

ABCD

多项选择第9题

BC

多项选择第10题

BC

多项选择第11题

AC 

三、填空题答案

填空第1题

protected;default;public

填空第2题

Object

填空第3题

java.lang.Character;java.lang.Boolean

填空第4题

Whatapleasure!

I

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

当前位置:首页 > 人文社科 > 教育学心理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1