Reputation: 27
int count = 0;
for (int i =0; i <8635; i++){
try {
line = Files.readAllLines(Paths.get("wordlist.txt")).get(i);
if (GridWords.contains(line)){
count++;
}
if (count > 1) {
ChoseRandomWord(randomword );
RemoveTheSimilarLetters(randomword, letters25 );
CreateTheGridContents(letters25, GridMap1, GridMap2);
ValidationOfTheGrid(GridMap1, GridMap2);
AskingTheUser(GridMap1, GridMap2);
}
} catch (IOException e) {
System.out.println(e);
}
}
I'm trying to check if what I did is the right way and why it kind of slow down the compiler when executing the program.
Upvotes: 0
Views: 40
Reputation: 11943
I suspect you want something like this:
int count = 0;
List<String> lines;
try {
lines = Files.readAllLines(Paths.get("wordlist.txt"));
} catch(IOException e) {
e.printStackTrace();
lines = Collections.emptyList();
// or return;
}
for (int i =0; i < lines.size(); i++){
String line = lines.get(i);
if (GridWords.contains(line)){
count++;
}
}
if (count > 1) {
ChoseRandomWord(randomword);
RemoveTheSimilarLetters(randomword, letters25 );
CreateTheGridContents(letters25, GridMap1, GridMap2);
ValidationOfTheGrid(GridMap1, GridMap2);
AskingTheUser(GridMap1, GridMap2);
}
This first counts the gridwords, then does the remaining logic. However your code is not doing anything with count
other than making sure at least 2 words were found.
Upvotes: 1