私のデータファイルは次のようになります(1列目-x; 2列目-y; 3列目):
46 80 2
95 75 2
78 85 2
59 54 1
81 52 2
57 78 1
72 46 2
タイプに応じて、ポイントの2つの異なる配列リストにx座標とy座標を保存しようとしています。
import java.util.*;
import java.util.ArrayList;
import java.io.*;
import java.awt.Point;
public class program {
public static void main(String []args) {
ArrayList knots = new ArrayList<Point>();
ArrayList zeros = new ArrayList<Point>();
List<Integer> list = new ArrayList<Integer>();
String line = null;
String file = "hepatitis_data1.txt";
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(file));
while((line = reader.readLine()) != null) {
String tmp[] = line.split(" +");
System.out.println(line);
for (String s:tmp) {
s = s.trim();
if(s.length() > 0) {
int i = Integer.parseInt(s.trim());
int r = Integer.parseInt(tmp[1].trim());
int g = Integer.parseInt(tmp[2].trim());
if (tmp[3].equals("1")) {
knots.add(new Point(r,g));
}
else if(tmp[3].equals("2")) {
zeros.add(new Point(r,g));
}
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
int total = knots.size() + zeros.size();
System.out.println("knot size" + knots.size());
System.out.println("zero size" + zeros.size());
System.out.println("total size" + total);
}
}
エラーは表示されませんが、正しいことをしていません。xy座標のペアが83あるため、合計値は83になるはずですが、合計は240になります。