java程序设计试题库 下载本文

《Java语言程序设计基础教程》

T2 t2=new T2(\ T3 t3=new T3(\ t1.start(); try {

t1.join();

} catch (InterruptedException e) {

// TODO Auto-generated catch block e.printStackTrace(); }

t2.start(); try {

t2.join();

} catch (InterruptedException e) {

// TODO Auto-generated catch block e.printStackTrace(); }

t3.start(); } }

class T1 extends Thread{ private String name; public T1(String name) { this.name=name; }

public void run() {

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

sleep(5);

} catch (InterruptedException e) {

// TODO Auto-generated catch block e.printStackTrace(); }

System.out.println(this.name+\循环\ } } }

class T2 extends Thread{ private String name;

49

49

50

《Java语言程序设计基础教程》

public T2(String name) { this.name=name; }

public void run() {

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

sleep(5);

} catch (InterruptedException e) {

// TODO Auto-generated catch block e.printStackTrace(); }

System.out.println(this.name+\循环\ } } }

class T3 extends Thread{ private String name; public T3(String name) { this.name=name; }

public void run() {

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

System.out.println(this.name+\循环\ } } }

第8章 文件和流

8.1单项选择题

1、 创建一个向文件“file.txt”追加内容的输出流对象的语句是( A. OutputStream out=new FileOutputStream(“file.txt”);

B. OutputStream out=new FileOutputStream(“file.txt”, “append”); C. FileOutputStream out=new FileOutputStream(“file.txt”, true); D. FileOutputStream out=new FileOutputStream(new file(“file.txt”)); 50

。 )