The_Other_One
Daemon Poster
- Messages
- 1,321
So here's a program I'm working on for class. It reads Teams.txt(just a list of a team name, a space, then a team's wins) It's then suppose to sort by the number of wins. I got it to read the teams and scores just fine and stick them each in arrays. The problem right now is that every time I do this test, just trying to see if it'll sort at all, I get errors. Not compiler errors, just errors when I run it...
I know it's not perfect, again, this is just a test. Don't ask how I plan to sort both arrays accordingly...I'm not to that point yet
------
import java.io.*;
import java.util.StringTokenizer;
public class Tournament
{
public static void main (String[] args) throws IOException
{
String[] scoresA = new String[64];
String[] teamsA = new String[64];
int x = 0;
String line, name, file = "Teams.txt";
FileReader fr = new FileReader (file);
BufferedReader inFile = new BufferedReader (fr);
line = inFile.readLine();
while (line != null)
{
StringTokenizer tokens = new StringTokenizer(line);
line = inFile.readLine();
teamsA[x] = tokens.nextToken();
scoresA[x] = tokens.nextToken();
x++;
}
inFile.close();
System.out.println(scoresA[1]);
java.util.Arrays.sort(teamsA);
System.out.println(scoresA[1]);
}
}
I know it's not perfect, again, this is just a test. Don't ask how I plan to sort both arrays accordingly...I'm not to that point yet
------
import java.io.*;
import java.util.StringTokenizer;
public class Tournament
{
public static void main (String[] args) throws IOException
{
String[] scoresA = new String[64];
String[] teamsA = new String[64];
int x = 0;
String line, name, file = "Teams.txt";
FileReader fr = new FileReader (file);
BufferedReader inFile = new BufferedReader (fr);
line = inFile.readLine();
while (line != null)
{
StringTokenizer tokens = new StringTokenizer(line);
line = inFile.readLine();
teamsA[x] = tokens.nextToken();
scoresA[x] = tokens.nextToken();
x++;
}
inFile.close();
System.out.println(scoresA[1]);
java.util.Arrays.sort(teamsA);
System.out.println(scoresA[1]);
}
}