更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
1、下面程序是打右图所示的图形。请完成填空。 

public class ShowTriangle { 

public static void main(String[] args) { 

final int ROWCOUNT=10; 

【1】 int COLUMNCOUNT=18; 

int i; 

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

for(int 【2】;j<COLUMNCOUNT;j++){ 

System.out.print(" "); 

for(int m=0; 【3】;m++) { 

System.out.print("#"); 

【4】; 

参考答案:【1】: final 【2】: j=9+i【3】: m<=2*i 【4】: System.out.println() 【5】 

                           # 

                        ### 

                     ##### 

                  ####### 

               ######### 

            ########### 

         ############# 

      ############### 

   ################# 

################### 

2、下面程序是求 1 到 100 的和。请完成填空。 

public class DemoSum { 

public static void main(String[] args) { 

int i=0,sum=0; 

do { 

【1】);; 

【2】; 

}while(【3】); 

System.out.println("1 to 100:"+sum); 

参考答案:【1】: sum+=i 【2】: i++ 【3】:i<=100

3、下面程序是抽象类的演示。请完成填空。 

abstract class Person { 

private String name; 

public Person(String name) { 

this.name = name; 

public 【1】 String getDescription();// 抽象方法 

public String getName() { 

return name; 

class Student 【2】 Person { 

private String specialty; 

public Student(String name, String specialty) { 

【3】(name); 

this.specialty = specialty; 

public String 【4】() { 

return "学生专业是:" + specialty; 

public class TestPerson { 

public static void main(String[] args) { 

Person person = new 【5】 (“张三峰”, “计算机科学与技术"); 

System.out.println(person.getName() + "," + 

person.getDescription()); 

参考答案:【1】: abstract 【2】: extends 【3】: super 【4】: getDescription 【5】: Student 

4、下面程序是接口及实现类的演示。请完成填空。 

interface Contents{ 

int value(); 

interface Destination{ 

String readLabel(); 

class Goods{ 

private class Content implements Contents { 

private int i= 11; 

@Override 

public int 【1】 () { 

return i; 

}protected class GDestination implements Destination { 

private String label; 

private GDestination(String whereto) { 

label=whereto; 

@Override 

public String 【2】 () { 

return label; 

public Destination dest(String s) { 

return new GDestination(s); 

public Contents cont() { 

return new Content( ); 

public class testInterface { 

public static void main(String[] args) { 

Goods p= new 【3】 (); 

Contents c = p. 【4】(); 

Destination d =p. 【5】("Beijing"); 

参考答案:【1】: value 【2】: readLabel 【3】: Goods 【4】: cont 【5】: dest 

5、下面程序是接口及实现类的演示。请完成填空。 

interface A { 

public static final int vcr = 6; 

public void print( ); 

class B 【1】 A{ 

@Override 

public void 【2】 () { 

System.out.println("调用 classB 的 print 方法"); 

public class TestAB { 

public static void main(String[ ] args) {System.out. println("输出接口中的常量值"+【3】.vcr); 

A a= new 【4】 (); 

a.print( ); 

参考答案:【1】: implements 【2】: print 【3】: A 【4】: B 

6、下面程序是接口及实现类的演示。请完成填空。 

interface Introduceable { 

public String 【1】 (); 

class Teacher 【2】 Introduceable { 

@Override 

public String detail() {//输出教师的详细信息 

return "本人是教师"; 

class Printer { 

public void print (String content) { 

System.out.println("开始打印:"); 

System.out.println(content); 

public class TestSchool { 

public static void main(String[] args) { 

Printer printer =【3】 Printer(); 

Teacher teacher=new 【4】 (); 

printer.print(【5】.detail()); 

参考答案:【1】: detail 【2】: implements 【3】: new 【4】: Teacher 【5】: teacher

7、下面程序是自定义异常处理。请完成填空。 

public class TestMyException { 

public void login( int num) throws MyException { 

if(num<0) { 

System.out.println(“登录帐号"+ num); 

throw 【1】 MyException(“登录帐号不能负数",3); 

public void manager() { 

try{ 

login(-100); 

}catch (【2】 e){ 

System.out.println("登录失败,出错种类为:"+ e.getIdnumber()); 

System.out.println("本次登录操作结束"); 

public static void main(String[ ] args){ 

TestMyException t= new 【3】 (); 

t.manager( ); 

class MyException extends Exception { 

private int idnumber; 

public MyException(String message, int idnumber) { 

【4】 (message); 

this.idnumber = idnumber; 

public int getIdnumber() { 

return 【5】; 

参考答案:【1】: new 【2】: MyException 【3】: TestMyException 【4】: super【5】: idnumber

8、下面程序是演示数组下标越界异常处理。请完成填空。 

public class TestThrow { 

static int array[]= {1,2,3,4,5}; 

public static int sum() 【1】 ArrayIndexOutOfBoundsException{ 

int s=0; 

for(int i=0;i<=5;i++) { 

s+=【2】; 

return 【3】; 

public static void main(String[] args) { 

try{ 

System.out. println("sum="+【4】 ()); 

}catch (【5】 e) { 

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

参考答案: 

【1】: throws 【2】: array[i]【3】: s 【4】: sum 【5】: ArrayIndexOutOfBoundsException 或 Exception

9、下面程序是通过 FileInputStream 实现从文件中数据读取各类数据。请完成填空。 

import java.io.*; 

public class DemoFileInputStream { 

public static void main(String[] args) 【1】 Exception { 

FileInputStream fin = new FileInputStream("dataFile.txt"); 

DataInputStream din = new DataInputStream(fin); 

int i = din. 【2】(); 

float f = din. 【3】(); 

boolean b = din. 【4】(); 

System.out.println("整数:" + i); 

System.out.println("浮点数:" + f); 

System.out.println("布尔量:" + b); 

din. 【5】(); 

参考答案:【1】: throws 【2】: readInt【3】:readFloat 【4】:readBoolean 【5】:close

10、下面程序是通过 FileInputStream 和 FileOutputStream 实现文件拷贝。请完成填空。 

import java.io.*; 

public class CopyFileDemo { 

public boolean copyFile(String src, String des) throws 【1】 { 

File srcFile, desFile; 

srcFile = new File(src); 

desFile = new File(des); 

FileInputStream fis = null; 

FileOutputStream fos = null; 

try{ 

desFile.createNewFile(); 

fis =new 【2】 (srcFile); 

fos =new 【3】 (desFile); 

int bytesRead; 

byte[] buf = new byte[4*1024]; //4KB 

while((bytesRead = fis.read(buf))!=【4】){ 

fos.write(buf, 0, bytesRead); 

} catch(IOException e){ 

System.out.println(e); 

return false; 

} finally { 

fos.flush( ); 

fos.close( ); 

fis.close( ); 

return true; 

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

CopyFileDemo cf=new CopyFileDemo(); 

String src = "test.txt"; 

String des = "testDes.txt"; 

if(cf. 【5】(src, des)) 

System.out.println("复制成功!"); 

else 

System. out. println("复制失败!"); 

参考答案: 

【1】: IOException 【2】: FileInputStream【3】:FileOutputStream 【4】:-1 【5】:copyFile

11、下面程序是通过 Runable 接口实现类实现多线程。请完成填空。 

public class ThreadTest { 

public static void main(String[] args) { 

Hello hello=【1】 Hello(); 

Thread thread=new Thread(【2】); 

thread. 【3】(); 

class Hello implements 【4】 { 

int i=0; 

@Override 

public void 【5】 () { 

while(true) { 

System.out.println("Hello:"+i++); 

if(i==5) break; 

参考答案:【1】: new 【2】: hello【3】:start 【4】: Runnable 【5】: run

12、下面程序是通过继承 Thread 类实现多线程。请完成填空。 

public class TheadTest 【1】 Thread{ 

public void 【2】 () { 

for(int i=1;i<=20;i++) { 

System.out.println("第"+i+"次显示 Hello"); 

try { 

Thread.sleep(1000); 

} catch (【3】 e) { 

e.printStackTrace(); 

public static void main(String[] args) { 

TheadTest theadTest=new 【4】 (); 

theadTest. 【5】(); 

参考答案: 

【1】: extends 【2】: run 【3】: InterruptedException 或 Exception 【4】: TheadTest 【5】: start