Java练习题03(3)
时间:2025-04-20
时间: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页)
上一篇:人教版初一语文下册教案全册
下一篇:人教版压强与浮力综合测试题