Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import java.util.Scanner;
import java.util.Arrays;
public class WordSearchRunner
public static void main(String[] args) throws FileNotFoundException
// instantiate Scanner object to read in from file
Scanner ws = new Scanner(new File("hidden.txt"));
// read in rows
int m = ws.nextInt();
// read in columns
int n = ws.nextInt();
// instantiate WordSearch object passing in number of rows & columns for 2D array
WordSearch wordSearch = new WordSearch(m, n);
// loop through the rows in the file
for(int r = 0; r < m; r++) //for every row in the array
for(int c = 0; c < n; c++) //for every column in that row
String s = ""; //create string s
s = s +; //add the next letter in the row to the string
wordSearch.setSpot(s, r, c);
ws.nextLine(); //move on to the next line
// read number of words to search for from file
int k = ws.nextInt();
// loops through the words
while(ws.hasNext()) //while there is a next set of characters after a whitespace
String s =; //add to the string
System.out.println(s + " " + wordSearch.inGrid(s)); //print the word and whether it is in the grid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.