Link to home
Start Free TrialLog in
Avatar of Pyro-San
Pyro-San

asked on

sorting arrays

here is a simple one, I need to sort these:
80 IsmatK
38 DavidW
58 DavidS
42 DavidR
where the int is the mark and the string is the login name, they are seperated into 2 arrays.
so-far this is what I have.

import java.io.*;
import java.awt.FileDialog;
import java.lang.*;

class three
/*Class to import text file of marks into an array, then sort it, then print it out
 to a screen sorted*/
{
      static public void main(String args[]) throws IOException
      {

            FileReader file = new FileReader("marks.txt");
                  
            //tokenize the input stream so that we can add it to an array
            StreamTokenizer inputStream = new StreamTokenizer(file);
            inputStream.wordChars(0x20,0x7F);
            
            //making my new arrays for the stuff
            String[] names = new String[4];
            int[] marks = new int[4];
            
            //heading test
            System.out.println("This is a heading \n");
            
            //initiate value i
                  
            //start adding the file into my arrays
            float tokenType = inputStream.nextToken();            
            for (int i = 0; tokenType != inputStream.TT_EOF; i++)
            {
                        
            marks[i] = (int)inputStream.nval;
            inputStream.nextToken();
            names[i] = inputStream.sval;
            tokenType = inputStream.nextToken();
            
            }
            file.close();
            
            System.out.println(marks.length);
      }

}

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CyTG
CyTG

as CEHJ said, make a comparator and do collections.sort on the list..
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept CEHJ's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

objects
EE Cleanup Volunteer