Java试题答案(全)

  • 格式:docx
  • 大小:14.69 KB
  • 文档页数:6

一、 选择题答案

选择第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)(String args[])

填空第4题

1

填空第5题

26

四、 编程题答案

1

public class HelloWorld

{

public static void main(String args[])

{

System.out.println("Hello,World!");

}

}

import java.awt.Graphics;

import java.applet.Applet;

public class HelloWorld extends Applet{

String s;

public void init(){

s="Hello World!";

}

public void paint(Graphics g){

g.drawString(s,25,25);

}

}

2

class yanghui

{

public static void main (String args[])

{

int i,j;

int yhlevel=10;

int yanghui[][];

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

yanghui=new int[yhlevel][];

for(i=0;i

yanghui[i]=new int[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

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

1 8 28 56 70 56 28 8 1

1 9 36 84 126 126 84 36 9 1

3

import java.io.*;

public class MemoController{

FileOutputStream fos;

OutputStreamWriter osw;

BufferedWriter bw;

public MemoController(){

try{

fos=new FileOutputStream("memo.txt",true);

osw=new OutputStreamWriter(fos);

bw=new BufferedWriter(osw);

}catch(FileNotFoundException e){};

}

public synchronized void append(String s){

try{

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

bw.flush();

bw.close();

osw.close();

fos.close();

}catch(IOException e){}

}

public static void main(String args[]){

MemoController mmc=new MemoController();

mmc.append("I am xubin ");

}

}

4

import java.io.*;

class Phones

{

static FileOutputStream fos;

public static final int lineLength = 81;

public static void main(String args[]) throws IOException

{

byte[] phone = new byte[lineLength];

byte[] name = new byte[lineLength];

int I;

try

{

fos = new FileOutputStream("phone.numbers");

}

catch(FileNotFoundException e)

{ }

while (true)

{

System.err.println("Enter a name (enter 'done' to quit)");

readLine(name);

if ("done".equalsIgnoreCase(new String(name,0,0,4)))

{

break;

} System.err.println("Enter the phone number");

readLine(phone);

for (int i=0;phone[i]!= 0;i++)

{

fos.write(phone[i]);

}

fos.write(',');

for (int i=0;name[i]!= 0;i++)

{

fos.write(name[i]);

}

fos.write('\n');

}

fos.close();

}

private static void readLine(byte line[]) throws IOException

{

int i=0,b=0;

while ((i

{

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

}

line[i]=(byte) 0;

}

}