Advertisement
Zeether

Updated word search

Sep 25th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.PrintStream;
  3. import java.util.Scanner;
  4.  
  5. public class WordSearch {
  6.  
  7.     public static void main(String[] args) throws Exception {
  8.  
  9.         Scanner sc = new Scanner(new File("puzzle.txt"));
  10.         // reading in rows and columns for the array
  11.         int numRows = sc.nextInt();
  12.         int numCols = sc.nextInt();
  13.         // creating an array for the puzzle
  14.         String[] stringArray = new String[numRows];
  15.  
  16.         // reading in the puzzle array
  17.         for (int i = 0; i < numRows; i++) {
  18.             stringArray[i] = sc.next();
  19.         }
  20.  
  21.         // reading in number of words to find in the array
  22.         int numWords = sc.nextInt();
  23.         String[] wordArray = new String[numWords];
  24.         for (int i = 0; i < numWords; i++) {
  25.             wordArray[i] = sc.next();
  26.         }
  27.  
  28.         // this will get the word to find in the array
  29.         for (int i = 0; i < numWords; i++) {
  30.             String wordToFind = wordArray[i];
  31.         }
  32.  
  33.         // iterating over the array to find words
  34.         for (int x = 0; x < numRows; x++) {
  35.             for (int y = 0; y < numCols; y++) {
  36.  
  37.            
  38.                
  39.                
  40.                
  41.             }
  42.         }
  43.  
  44.         sc.close();
  45.     }
  46.  
  47.     // this method will be used to check for the words
  48.     private static boolean wordCheck(String puzzle[], String wordToFind, int xpos,
  49.             int ypos) {
  50.         for (int i = 0; i < xpos; i++) { // along x axis positive
  51.             if (puzzle[i].charAt(xpos) == wordToFind.charAt(i)) {
  52.                 //System.out.println("Finding word");
  53.                 return true;
  54.             } else {
  55.                 //System.out.println("Couldn't find the word");
  56.                 return false;
  57.             }
  58.         }
  59.        
  60.         for (int i = 0; i < ypos; i++){ // y axis positive
  61.             if (puzzle[i].charAt(ypos) == wordToFind.charAt(i)){
  62.                 //System.out.println("Finding word");
  63.                 return true;
  64.             } else {
  65.                 //System.out.println("Couldn't find the word");
  66.                 return false;
  67.             }
  68.         }
  69.        
  70.         for (int i = 0; i < ypos; i++){ // negative x axis
  71.             if (puzzle[i].charAt(xpos) == wordToFind.charAt(i)){
  72.                 //System.out.println("Finding word");
  73.                 return true;
  74.             } else {
  75.                 //System.out.println("Couldn't find the word");
  76.                 return false;
  77.             }
  78.            
  79.         }
  80.        
  81.         for (int i = 0; i < xpos; i++){ // negative y axis
  82.             if (puzzle[i].charAt(ypos) == wordToFind.charAt(i)){
  83.                 //System.out.println("Finding word");
  84.                 return true;
  85.             } else {
  86.                 //System.out.println("Couldn't find the word");
  87.                 return false;
  88.             }
  89.         }
  90.        
  91.        
  92.        
  93.         return false;
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement