阅读以下程序,给出运行结果。
classMultiCatch{
publicstaticvoidmain(Stringargs[]){
try{
inta=args.length;
intb=44/a;
intc[]={2,6};
c[44]=100;
System.out.println("b="+b);
}catch(ArithmeticExceptione){
System.out.println("除0异常");
}catch(ArrayIndexOutOfBoundsExceptione){
System.out.println("数组超越边界异常");
}finally{
System.out.println("程序执行结束");
}
}
}
运行结果是:
A.异常就是有语法错误的程序
B.异常是程序运行时可能遇到的特殊情况,需要捕获并处理
C.异常可以用try{}catch{}程序块来捕获并处理
D.异常会导致程序的崩溃
A.一个try代码段必须和一个catch代码段相对应
B.非GUl程序产生异常时,若没有合适的异常处理与之匹配, 则程序将恢复正常的运行
C.当异常被抛出时,可能产生由于没有与之匹配的catch子句而过早地返回的情况
D.catch(Exceptione)不能捕获异常抛出的任何类型
A.异常的基类为Exception,所有异常都必须直接或者间接继承它
B.异常可以用try{...}catch(Exceptione){...}来捕获并进行处理
C.如果某异常继承RuntimeException,则该异常可以不被声明
D.异常可以随便处理,而不是抛给外层的程序进行处理
程序阅读:class Myexception extends Exception
{
Myexception ()
{
super();
}
Myexception(String msg)
{
super(msg);
}
}
public class Test
{
public static void main(String args[])
{
try
{
throw new Myexception(“自定义异常”);
}
catch(Myexception e)
{
System.out.println(e.getMessage());
}
}
}
下列程序的功能是每隔一秒钟输出一个字符串“Hello!”。
publicclassC3101implementsRunnable
{
publicstaticvoidmain(Stringargs[])
{
C3101t=newC3101();
Threadtt=newThread(t);
tt.start();
}
publicvoidrun()
{
for(;;)
{
try{
();
}catch(()){}
System.out.println("Hello");
}
}
}
阅读下列程序,请写出该程的功能。
import java.io.*;
public class Class34
{
public static void main(String[] args)
{
File inputFile=new File("file1.txt");
File utputFile=new File("file2.txt");
int ch;
try
{
FileReader in=new FileReader(inputFile);
FileWriter ut=new FileWriter(outputFile);
while((ch=in.read())!=-1)out.write(ch);
in.close();out.close();
}
catch(FileNotFoundExceptione1)}
{System.out.println("文件没有找到!"+e1);}
catch(IOException e2)
{System.out.println("FilereadError!"+e2);}
}
}
import java.io.*;
public class Test {
public static void main(String args[]) {
try {
String s = "ABCDE" byte b[]=s.getBytes()
FileOutputStream file =
new FileOutputStream("test.txt", true)
file.write(b) file.close() }
catch(IOException e) {
System.out.println(e.toString()) }
}
}
A、ABCABC
B、ABCDE
C、Test
D、ABCDEABCDEABCDE
完成下列各题 The people who lives in the far North are called Eskimos(爱斯基摩人).In the world of ice and snow it is 21 to grow plants for food.The Eskimos must hunt and fish during the whole year to 22 themselves and their families with food.In winter,they hunt the seal(海豹) 23 the polar(极地的)bear.When they hunt the seal,they 24 a hole in the ice and try to 25 the seal when it comes up to breathe. In summer,the Eskimos hunt 26 animals。and they also hunt birds and catch fish. 27 that is useful is saved.The Eskimos use the meat from animals for food.They melt(融化)the fat from their bodies and use the 28 as fuel(燃料).They make tools out of animals bones.The skin and furs of animals are used for making clothing. If an Eskimo is 29 lucky,he may kill a whale(鲸鱼), 30 a dead whale may wash up on the shore near his house.The whale is an especially useful animal,because it gives a great 31 of oil. There is 32 wood at all where the Eskimos live.Eskimos 33 all their wood from the sea.Sometimes floating wood from places.farther south washes up on the shore. Most Eskimo houses are 34 of stones.Instead of a door,there is a long,low tunnel (地道) 35 into the house.People have to crawl(爬)through the tunnel in order to enter the house.
A.important
B.impossible
C.impolite
D.interesting