-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTryCatchFinally.java
More file actions
23 lines (19 loc) · 806 Bytes
/
TryCatchFinally.java
File metadata and controls
23 lines (19 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package bigjava;
import java.util.Scanner;
public class TryCatchFinally {
public static void main(String[] args) {
try{ //try语句中包含可能出现异常的程序代码
Scanner input=new Scanner(System.in);
int[] age=new int[3];
for (int i = 0; i <age.length+1; i++) {
System.out.print("请输第"+(i+1)+"的年龄:");
age[i]=input.nextInt();
}
}catch(Exception ex){ //catch语句块用来获取异常信息
System.out.println("发生异常错误");
ex.printStackTrace(); //输出异常性质
}finally {
System.out.println("已成功显示年龄信息");
}
}
}