getWord() を介して返される文字列 randomWord を取得する必要があります
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;
}
これを機能させる方法はありますか?
String word = randomWord ;
randomWord が getWord() の文字列ではないため、唯一のエラーが発生します
。
では、randomWord を getWord() で使用できるようにするにはどうすればよいでしょうか。
編集: 既存のプライベートを変更することはできません。プライベートのままにしておく必要があります。