-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListOfNumbers.java
39 lines (34 loc) · 1.13 KB
/
ListOfNumbers.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
36
37
38
39
import java.io.*;
import java.util.List;
import java.util.ArrayList;
public class ListOfNumbers{
private List<Integer> list;
private static final int SIZE = 10;
public ListOfNumbers(){
list = new ArrayList<Integer>(SIZE);
for(int i = 0; i < SIZE; i++){
list.add(new Integer(i));
}
}
public void writeList(){
PrintWriter out = null;
try{
System.out.println("Entering" + " try statement");
out = new PrintWriter(new FileWriter("OutFile.txt"));
for(int i = 0; i < SIZE; i++){
out.println("Value at: " + i + " = " + list.get(i));
}
} catch(IndexOutOfBoundsException e){
System.err.println("Caught IndexOutOfBoundsException: " + e.getMessage());
} catch(IOException e){
System.err.println("Caught IOException: " + e.getMessage());
} finally{
if(out != null){
System.out.println("Closing PrintWriter");
out.close();
} else{
System.out.println("PrintWriter not open");
}
}
}
}