Created
December 2, 2012 19:22
-
-
Save benfb/4190542 to your computer and use it in GitHub Desktop.
WordSearchRunner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.io.*; | |
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 + ws.next(); //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 = ws.next(); //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