Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Anagrams

Thu Apr 05, 2012 12:36 pm

Hi, I'm supposed to write an algorithm sorting out anagrams from the given list. So far I got the list read in eclipse, but struggling with the sorting part. Can anyone help me out? This is my code so far

Code:
package Tutorial5;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;


public class Anagrams {

   /**
    * @param args
    */
   public static void main(String[] args) {
      
      try{
         FileInputStream fis = new FileInputStream("src/Tutorial5/words"); //locate and open the txt.file
         
         DataInputStream dis = new DataInputStream(fis); //get the words from the txt.file
         
         BufferedReader br = new BufferedReader(new InputStreamReader(dis));
         
         String SLine;
         
         
         while ((SLine = br.readLine()) != null) //read the txt.file line by line
         {
            System.out.println(SLine); //print out the words
      }
      
      dis.close(); //close the DataInputStream
      
   }
      catch (Exception e) //see if there is any exception to catch
      {
         System.err.println("Error: " + e.getMessage());
      }
      
}
}


Related to
java/java-anagram-t5455.html



Post a reply