java复习题答案Word文档格式.docx
- 文档编号:18848611
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:21
- 大小:20.86KB
java复习题答案Word文档格式.docx
《java复习题答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《java复习题答案Word文档格式.docx(21页珍藏版)》请在冰豆网上搜索。
多项选择第9题
AB
多项选择第10题
CD
多项选择第11题
多项选择第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
四、编程题答案
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.length;
i++)
yanghui[i]=newint[i+1];
yanghui[0][0]=1;
for(i=1;
i<
yanghui[i][0]=1;
for(j=1;
j<
yanghui[i].length-1;
j++)
yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];
yanghui[i][yanghui[i].length-1]=1;
for(i=0;
for(j=0;
yanghui[i].length;
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){
bw.write(s,0,s.length());
bw.flush();
bw.close();
osw.close();
fos.close();
}catch(IOExceptione){}
publicstaticvoidmain(Stringargs[]){
MemoControllermmc=newMemoController();
mmc.append("
Iamxubin"
4
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;
}
Enterthephonenumber"
readLine(phone);
for(inti=0;
phone[i]!
=0;
i++)
fos.write(phone[i]);
fos.write('
'
name[i]!
fos.write(name[i]);
\n'
}
privatestaticvoidreadLine(byteline[])throwsIOException
{
inti=0,b=0;
while((i<
lineLength-1)&
&
((b=System.in.read())!
='
))
line[i++]=(byte)b;
line[i]=(byte)0;
}
复习题2
二、多项选择题答案
AD
BCD
ABD
多项选择第14题
ABD
三、填空题答案
Collection,List,Map,Set
7
因为在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();
Point2:
+Point2.x+"
+Point2.y+"
PointPoint3=newPoint(5,6);
Point1.setPoint(Point3);
}
编程第2题
classFileCopy
publicstaticvoidmain(String[]args)
FileInputStreamin;
FileOutputStreamout;
if(args.length<
2)
Usage:
javacopysrcfiledestfile"
System.exit(-1);
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);
Error:
+e);
编程第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
D
选择第12题
B
ADE
ABCD
AC
protected;
default;
public
Object
java.lang.Character;
java.lang.Boolean
Whatapleasure!
I
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 复习题 答案