Hi. Can somebody help me? I am trying to create a program that reads random line from a file and displays them.
My problem is, it keeps repeating the same line after a few tries. i have 8 total lines from my file...
this is my code so far...
public static String getWord()
{
int randNum;
String quests = " ";
try
{
Scanner inFile = new Scanner(new FileReader("game.txt"));
randNum = (int) (Math.random() * 8);
for(int i = 0; i<=randNum-1; i++)
quests = inFile.nextLine();
return quests;
}
catch(Exception e)
{
System.exit(-1);
}
return quests;
}
thanks in advance! :)