//捕捉被零除的异常(ArithmeticException类型的异常)
import java.io.*;
public class ExceptionTester3 {
public static void main(String args[]) {
int number1=0,number2=0,result=0;
try {
System.out.println("Enter the first number:");
number1=Integer.valueOf(Keyboard.getString()).intValue();
System.out.println("Enter the second number:");
number2=Integer.valueOf(Keyboard.getString()).intValue();
result=number1/number2;
}catch(NumberFormatException e) {
System.out.println("Invalid integer entered!");
System.exit(-1);
}catch(ArithmeticExecption e) {
System.out.println("Second number is 0,cannot do division!");
System.exit(-1);
}
System.out.println(number1+"/"+number2+"="+result);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Keyboard cannot be resolved
Keyboard cannot be resolved
ArithmeticExecption cannot be resolved to a type
at ExceptionTester3.main(ExceptionTester3.java:8)