Demo entry 6717223

java

   

Submitted by anonymous on Feb 23, 2018 at 12:55
Language: Java. Code size: 778 Bytes.

public String[] getWordForLevel() throws IOException{
    ArrayList<String> list = new ArrayList<>();
    File file;
    if(level == 4){
        file =new File("lib/SAYINGS.txt");
    }
    else{
        file =new File("lib/ANAGRAM.txt");
    }
    Scanner in = null;
    try {
        in = new Scanner(file);
        while(in.hasNext())
        {
            String line=in.nextLine();
            if(level == 4){
                list.add(line);     
            } 
            else if(line.length() == numberOfletters){
                list.add(line);                       
            }
        }    
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    String[] arr = list.toArray(new String[0]);
    return arr;  
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).