Below is my code that I have so far. I only started programming a couple weeks ago so I am new to all of this, and I cannot figure out how to randomly select and print a word. Where do I start?
public static String randomWord(String fileName)
throws FileNotFoundException {
int fileSize = countWords(fileName);
int N = (int) (fileSize*Math.random());
Scanner inFile = new Scanner(new File(fileName));
String word;
while (inFile.hasNext()) {
word = inFile.next();
}
inFile.close();
return word;
}
Nth word, correct? Can you think of a way to stop at theNth word?