-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDraft00.java
More file actions
32 lines (27 loc) · 911 Bytes
/
Copy pathDraft00.java
File metadata and controls
32 lines (27 loc) · 911 Bytes
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
// import java.io.*;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
class Draft00 {
// usage:
// javac draft00.java
// java draft00
public static void main(String args[]) {
System.out.println("Hello, World");
Draft00.test_writeList();
}
public static void test_writeList() {
try {
// The FileWriter constructor throws IOException, which must be caught.
PrintWriter out = new PrintWriter(new FileWriter("tbd00.txt"));
List<Integer> list = Arrays.asList(2, 3, 3);
for (int i = 0; i < list.size(); i++) {
// The get(int) method throws IndexOutOfBoundsException, which must be caught.
out.println("Value at: " + i + " = " + list.get(i));
}
out.close();
} catch (Exception e) {
}
}
}