I need to get the string randomWord to return through getWord()
private static void setUpDictionary() throws IOException
{
Scanner fileScan;
String[] words = new String[25];
fileScan = new Scanner (new File("dictionary.dat"));
int n=0;
while (fileScan.hasNext())
{
words[n] = fileScan.next();
n++;
}
int rand = (int) (Math.random()*n);
String randomWord = words[rand];
System.out.println("TEST THIS IS RANDOM WORD ..." + randomWord);
fileScan.close();
}
//Returns random word from dictionary array
private static String getWord()
{
String word = randomWord ;
return word;
}
Any ideas how to get this to work?
The only error comes from
String word = randomWord ;
because randomWord isn't a string in getWord().
So how do I make randomWord available to getWord()?
EDITS: I cannot change any existing private, they have to stay private.