Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package htsprog1;
- import java.util.*;
- import java.io.*;
- /**
- * Unscramble a list of words.
- * @author Jorne
- */
- public class HTSProg1
- {
- public static ArrayList<String> wordList = new ArrayList<String>();
- public static ArrayList<String> scrambledList = new ArrayList<String>();
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- readWordList();
- for(int i=0;i<wordList.size();++i)
- {
- System.out.println(wordList.get(i));
- }
- }
- public ArrayList<String> limit(String s)
- {
- /**
- * Returns an ArrayList with all the strings of the same length
- */
- ArrayList<String> limitedList = new ArrayList<String>();
- int l = s.length();
- for(int i=0; i<wordList.size();++i)
- {
- if(wordList.get(i).length() == l)
- {
- limitedList.add(s);
- }
- }
- return limitedList;
- }
- public static void readWordList()
- {
- try
- {
- FileInputStream fstream = new FileInputStream("C:\\Files\\stuff\\wordlist.txt");
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- while ((strLine = br.readLine()) != null)
- {
- wordList.add(strLine);
- }
- //Close the input stream
- in.close();
- }
- catch (Exception e)
- {//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment