import java.io.*;
import java.util.Vector;
public class ListOfNumbers7 {
private Vector victor;
private static final int SIZE = 10;
public ListOfNumbers7 () {
victor = new Vector(SIZE);
for (int i = 0; i < SIZE; i++) {
victor.addElement(new Integer(i));
}
}
public void writeList() throws ArrayIndexOutOfBoundsException {
PrintWriter out = null;
out = new PrintWriter(new FileWriter("OutFile.txt"));
int qqq = 12;
for (int i = 0; i < qqq; i++) {
if (qqq>=10) throw new ArrayIndexOutOfBoundsException();
out.println("Value at: " + i + " = " + victor.elementAt(i));
}
out.close();
}
public static void main(String[] args) {
ListOfNumbers7 l = new ListOfNumbers7();
l.writeList();
}
}
2007-01-10 03:00:02 · 1 個解答 · 發問者 ? 3 in 電腦與網際網路 ➔ 程式設計
請參考我的做法
import java.io.*;
import java.util.Vector;
public class ListOfNumbers7 {
private Vector victor;
private static final int SIZE = 10;
public ListOfNumbers7 () {
victor = new Vector(SIZE);
for (int i = 0; i < SIZE; i++) {
victor.addElement(new Integer(i));
}
}
public void writeList() throws Exception {
PrintWriter out = null;
out = new PrintWriter(new FileWriter("OutFile.txt"));
// int qqq = 12;
for (int i = 0; i < victor.size(); i++) {
// if (qqq>=10) throw new ArrayIndexOutOfBoundsException();
out.println("Value at: " + i + " = " + victor.elementAt(i));
}
out.close();
}
public static void main(String[] args) throws Exception {
ListOfNumbers7 l = new ListOfNumbers7();
l.writeList();
}
}
2007-01-10 07:04:21 · answer #1 · answered by ? 7 · 0⤊ 0⤋