I wrote this program to read a cvs file I was given. The file has 921 rows and 11 columns. After reading the file, how do I make it an array and then find the averages of the 11 columns? Help would be much appreciated, thanks!
Here are my codes at this point:
package applesa;
import java.io.File;
import java.util.Scanner;
public class readfile {
private Scanner x;
public void openFile() {
try{
x = new Scanner(new File("csvfile"));
}
catch(Exception e){
System.out.println("Could not find file");
}
}
public void readFile(){
while(x.hasNext()){
String a = x.next();
String b = x.next();
String c = x.next();
String d = x.next();
String e = x.next();
String f = x.next();
String g = x.next();
String h = x.next();
String i = x.next();
String j = x.next();
String k = x.next();
System.out.printf("%s %s %s %s %s %s %s %s %s %s %s\n", a,b,c,d,e,f,g,h,i,j,k);
}
}
public void closeFile() {
x.close();
}
}
With a main method:
package applesa;
public class applesa {
public static void main (String[] args){
readfile r = new readfile();
r.openFile();
r.readFile();
r.closeFile();
}
}