私は .csv ファイルを持っていて、Java でそれを読み取る方法を理解しています。私の問題は、ファイル内の値を文字列に入れ、文字列を読み取ってこれらの値を計算できるようにしたいことです。
アリス・ジョーンズ,80,90,100,95,75,85,90,100,90,92 ボブ・
マンフレッド,98,89,87,89,9,98,7,89,98,78
これらは値ですが、各名前の横にあるすべての整数を合計して平均を作成するにはどうすればよいでしょうか? 私の最大の問題は、Whileループにあるファイルを読んだときに、コンソールに上に見えるように行を出力できたが、Whileループの外に値を出力したいときに、文字列がそうではないと言ったことでした存在しないので、何もないと値を計算できません。
import java.io.*;
import java.util.*;
public class Grades {
public static void main(String args[]) throws IOException
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("filescores.csv");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
String line = strLine
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}