So for a homework problem I basically need to write a program that reads data from a text file, then input it into an array which I can later use for other functions. The main problem is writing to the arrays. I can't figure out how to do it properly =/
import java.io.*;
import java.util.*;
public class reader
{
public static void main (String []args)
{
String[][] quizScores = new String[40][6];
{
try
{
FileReader input = new FileReader("quizscore.txt");
BufferedReader bufferInput = new BufferedReader(input);
String line;
while ((line = bufferInput.readLine ()) !=null )
{
for (int l = 0; l <=40; l++)
{
for (int i = 0 ; i <=6; i++)
{
StringTokenizer st = new StringTokenizer(line);
quizScores[l][i] = st.nextToken();
}
System.out.println("Read:" + line);
System.out.println(quizScores[4][2]);
}
}
}
catch (IOException e)
{
System.out.println("Error:" + e);
}
}
}
}
Executing this code, gives an error on the line,
quizScores[l][i] = st.nextToken();
Are my loops for the array increments wrong? When I try to run the program, I get an out of bounds error. So I'm kinda lost :(??? Also assuming I get the loop fixed, if I wanted to find the maxs and mins and averages of each column, what kinda function would I write? From my understanding, the Math.Max and Math.Min functions only take input such as this (int a, int b). So in order to use something like that, I would have to convert the entire array from String -> Int, but then where do I go from there? Does the Math.Max function have some kinda overriding function where I can just make it read the whole arrays column? And if there's other functions I can use it'd be nice if I could be enlightened to them since our teacher has only taught us the Math.max/min/etc functions which to me, do not seem to serve this problem properly.
The file contains information like this,
4532 011 017 081 032 077
5678 020 012 045 078 034
6134 034 080 055 078 045
7874 060 100 056 078 078
8026 070 010 066 078 056
9893 034 009 077 078 020
1947 045 040 088 078 055
2877 055 050 099 078 080