Java练习题03(3)

时间:2025-04-20

java练习题

class J_Exception extends Exception { }

public class J_Test {

public static void main(String[] args) {

try {

int i = System.in.read();

if(i == '0')

throw new J_Exception();

System.out.print("1");

}

catch(IOException ex) {

System.out.print("2");

}

catch(J_Exception ex) {

System.out.print("3");

}

finally {

System.out.println("4");

}

}

}

输出结果:

4、假设文本文件“test.txt”存在。读程序,写出编译和运行该程序时的输出结果。

import java.io.*;

public class J_Test {

public static void main(String[] args) {

try {

int ch;

FileReader f = new FileReader("test.txt");

while((ch = f.read()) != -1)

System.out.print((char)ch);

f.close();

}

catch(IOException ex) {

System.out.println(ex);

}

System.out.println();

}

}

输出结果:

5、读程序,从A、B、C、D中选择最合适的答案。

public class J_Test extends Thread {

static J_Test m_a, m_b;

public void run() {

System.out.println((this == m_a ? "A" : "B") + " sleeps.");

try {

Java练习题3(第3页 共5页)

Java练习题03(3).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219