Hello,
I am tasked with coding a program that allows the user to guess a randomized word from an array with 10 slots. The pre-chosen words are stored in a wordguess.DAT file and must be imported into a string array. I have looked on other Java forums and most of the examples use methods that I have not learned yet, so it is hard for me to understand what is really going on. Can anyone help?
public static void init() { //sets up the console scanner Scanner myScanner = new Scanner(System.in); myScanner.useDelimiter(System.getProperty("line.separator")); //sets up the in-file along with the in-file scanner //inFile = new File("wordguess.dat"); //datScanner = new Scanner(inFile); //datScanner.useDelimiter(System.getProperty("line.separator")); //read input into an array with a try-catch try { wordArray = new ArrayList<String>(); Scanner datScanner = new Scanner(new File("wordguess")); while(datScanner.hasNextLine()); { wordArray.add(datScanner.nextLine()); } } catch(IOException e) { System.out.println("File not found."); } }
--- Update ---
My teacher doesn't want us to use ArrayList since we have not talked about it yet in class. He wants the array to be basic.