daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package htsprog1;
  6. import java.util.*;
  7. import java.io.*;
  8. /**
  9.  * Unscramble a list of words.
  10.  * @author Jorne
  11.  */
  12.  
  13. public class HTSProg1
  14. {
  15.     public static ArrayList<String> wordList = new ArrayList<String>();
  16.     public static ArrayList<String> scrambledList = new ArrayList<String>();
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args)
  21.     {
  22.         readWordList();
  23.         for(int i=0;i<wordList.size();++i)
  24.         {
  25.                System.out.println(wordList.get(i));
  26.         }
  27.     }
  28.     public ArrayList<String> limit(String s)
  29.     {
  30.         /**
  31.          * Returns an ArrayList with all the strings of the same length
  32.          */
  33.         ArrayList<String> limitedList = new ArrayList<String>();
  34.         int l = s.length();
  35.         for(int i=0; i<wordList.size();++i)
  36.         {
  37.             if(wordList.get(i).length() == l)
  38.             {
  39.                 limitedList.add(s);
  40.             }
  41.         }
  42.         return limitedList;
  43.     }
  44.     public static void readWordList()
  45.     {
  46.         try
  47.         {
  48.           FileInputStream fstream = new FileInputStream("C:\\Files\\stuff\\wordlist.txt");
  49.           DataInputStream in = new DataInputStream(fstream);
  50.           BufferedReader br = new BufferedReader(new InputStreamReader(in));
  51.           String strLine;
  52.           while ((strLine = br.readLine()) != null)
  53.           {
  54.             wordList.add(strLine);
  55.           }
  56.           //Close the input stream
  57.           in.close();
  58.         }
  59.         catch (Exception e)
  60.         {//Catch exception if any
  61.             System.err.println("Error: " + e.getMessage());
  62.         }
  63.   }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top