IdNameYearCurrentCumulative
16,梅麗莎·威爾,3,5,9
娜奧米·托馬斯
21,RonaldoGomes,3,1,11
22日,薩姆德爾普雷特,2,4,10
2,阿貝·斯托裏,3,4,6
安東尼·塔布林
內森·本特利,3,2,19
您使用本文檔的內容並嘗試以下過程。
導入Java . io . buffered reader;
導入Java . io . buffered writer;
導入Java . io . filereader;
導入Java . io . filewriter;
導入Java . util . ArrayList;
導入Java . util . list;
公共類測試{
公共靜態void main(String[] args)引發異常{
file reader fr = new FileReader(" H:\ \ test . txt ");
BufferedReader br =新buffered reader(fr);
int row = 1;
int sum1 = 0,sum 2 = 0;
file writer fw = new file writer(" H:\ \ new . txt ");
buffered writer bw = new buffered writer(fw);
bw . write(" idnameearcurrentcumulative ");
bw . newline();
列表& lt字符串& gtfirst = new ArrayList & lt字符串& gt();
while (br.ready()) {
if (row++ == 1) {
br . readline();
繼續;
}
string line = br . readline();
String[] array = line.split(",",5);
String tmp = array[1]。修剪()。子串(0,1);
如果(!first.contains(tmp)) {
sum1 += toInt(array[3])。trim());
sum2 += toInt(array[4])。trim());
bw.write(行);
bw . newline();
first . add(tmp);
}
}
bw . write(" sum:\ t \ t \ t \ t "+sum 1+" \ t "+sum 2);
bw . newline();
bw . write(" average:\ t \ t \ t "+(sum 1/(first . size()* 1.0))+" \ t "
+sum 2/(first . size()* 1.0));
br . close();
fr . close();
bw . close();
fw . close();
}
public static int to int(String str){
嘗試{
返回integer . parse int(str);
} catch(異常e) {
返回0;
}
}
}