手机版

Java练习题03(3)

时间:2025-04-21   来源:未知    
字号:

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文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)