cry…catch使用
package yichang_test1;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TestException2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a,b;
try {
System.out.println("请输入被除数:");
a = in.nextInt();
System.out.println("请输入除数:");
b = in.nextInt();
System.out.println("两数相除结果为:"+a / b);
System.out.println("感谢使用本程序");
return;
}catch (Exception e) {
e.printStackTrace();
System.exit(1);
}finally {
System.out.println("总程序被执行");
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42