I am working on a solution for school. The purpose is to write a class that reads from standard input a file containing several integers that must be placed in an array. From here it is necessary to write methods that determine the mean, average, maximum, minimum and standard deviation.
It reads like this:
45
56
67
78
89 etc ...
So, I assume that I need to create a list of arrays (since the length is undefined) and use a scanner to read each line for an integer, and then create methods that will highlight what I need. However, I do not understand how to use FileReader and Scanner correctly. I am currently running BlueJ. The text file is in the project folder, but the file was never found by the code.
Here is what I still have.
import java.io.*; import java.util.*; import java.math.*; public class DescriptiveStats { public DescriptiveStats(){} public FileReader file = new FileReader("students.txt"); public static void main(String[] args) throws IOException { try{ List<Integer> scores = new ArrayList<Integer>(); Scanner sc = new Scanner(file); while(sc.hasNext()) { scores.add(sc.nextInt()); } sc.close(); } catch(Exception e) { e.printStackTrace(); } }
source share