我有一個.txt文檔以及關於它們的名稱和信息列表。 我想讀取.txt文檔並有權訪問數據,然後我想使用數據中的信息來計算平均值,最高值和最低值。 這是.txt文檔中的信息。Java:讀取.txt文檔並可以訪問數據
First Name, Surname, Age, Weight, Height
Tim, Simon, 37, 82, 178
barry, White, 21, 70, 176
Jason, Brink, 19, 67, 165
Caren, Dick, 22, 105, 200
Jackson, Michael, 81, 60, 170
Jerry, Springton, 6, 20, 111
我希望能夠根據這些數據計算平均值。 以下是我如何讀取數據。
public static void main(String[] args) {
File file = new File("/Users/Len/Desktop/TextReader/src/example.txt");
try {
Scanner input = new Scanner(file);
while (input.hasNext()) {
String num = input.nextLine();
System.out.println(num);
}
} catch (FileNotFoundException e) {
System.err.format("File Does Not Exist\n");
}
}
你在哪裏卡住了? –
@ModusTollens我設法讀出數據。逐行打印出來。但我是Swift開發人員,如何將這些數據添加到數組或字典中來處理它? –