Код: Выделить всё
import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class MainClass {
public static double mean_file(String file_name) {
/*
* Calculates the average of numbers from a text file
*/
File data = new File(file_name);
double sum = 0;
ArrayList list_of_numbers = new ArrayList();
Scanner read = new Scanner(data);
while (read.hasNextLine()) {
try {
int nb = Integer.parseInt(read.nextLine());
list_of_numbers.add(nb);
} catch (NumberFormatException n) {
JOptionPane.showOptionDialog(null, "File content error", "Files must only contain one number per line!", 0, 1, null, null, "OK");
}
}
for (int c=0; c
Подробнее здесь: [url]https://stackoverflow.com/questions/79321014/read-data-into-an-arraylist[/url]
Мобильная версия