-
Notifications
You must be signed in to change notification settings - Fork 0
/
tryfinally.java
35 lines (33 loc) · 1.14 KB
/
tryfinally.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
public class tryfinally {
public static void main(String[] args) throws IOException {
// try {
// // exception generation
// int j = 9 / 0;
// System.out.println("i will not be printed");
// } catch (Exception e) {
// System.out.println("exception occured");
// } finally {
// System.out.println("finally i executed, i will execute in any circumstance");
// }
int num;
BufferedReader br = null;
// try {
// InputStreamReader in = new InputStreamReader(System.in);
// br = new BufferedReader(in)
// num = Integer.parseInt(br.readLine());
// System.out.println(num);
// } catch (Exception e) {
// // TODO: handle exception
// } finally {
// br.close();
// }
// try with resources
try (BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in))) {
num = Integer.parseInt(br.readLine());
}
}
}