java - Making my program read 3 line individually -


this program reads file away lecture file readers i'm winging it. program reads in 1 line , prints out top 3 values works 1 line in file.

import java.util.*; import java.io.*; public class processdatderefile {     public static void main (string[] args)throws ioexception{         list namenum=readm("data/raw.txt");         dataprocess(namenum);     }      public static list readm(string filename)throws ioexception{         scanner fr=new scanner(new filereader(filename));         list<string>namenum=new arraylist<string>();         while(fr.hasnext()){             namenum.add(fr.next());         }         fr.close();         collections.sort(namenum,collections.reverseorder());         return namenum;     }      public static void dataprocess(list namenum)throws ioexception{         for(int i=0;i<4;i++){             system.out.printf("%s ",namenum.get(i));         }         system.out.println("");     } } 

raw.txt contains

mary 45 87 23 76 joe 34 76 12 78 34 87 anne 90 5 99 

the program needs print each name , top 3 scores on individual lines. lengthy replies welcome. in advance.

what trying sort here.

   collections.sort(namenum,collections.reverseorder()); 

namenum list of individual item in file.

  mary 45 87 23 76 

each item in list seperate item in list.

you need use nextline(). each line need skip first token name , convert rest of data on line in integer array , reverse sort on that.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -