I am confused on what BNF grammar actually is. As of right now, I have a text file called lol.txt and my code prints out a random line in the file. However, I need to pick a adj, prep, noun, etc to make a random sentence. Is my logical approach wrong?
FileInputStream wordsFile = new FileInputStream("lol.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(wordsFile));
String[] strWordArray;
strWordArray = new String[10];
for (int i = 0; i < strWordArray.length; i++)
{
strWordArray[i] = br.readLine();
}
wordsFile.close();
Random rand = new Random();
String Word = strWordArray[rand.nextInt(strWordArray.length)];
System.out.println(Word);
}
Aucun commentaire:
Enregistrer un commentaire