title: how to traverse though a 2d char array searching for words in java?
body: <p>I am having trouble with a school assignment and would really appreciate some insight. I am asked to create a wordsearch using a 25x25 2d char array and somehow go through that array by developing an algorithm that will search through it to find 21 pre-defined words.</p>
  
  <p>So far I have been able to create a ragged array of the words that I need to find and the 2d array with the chars placed in each position.</p>
  
  <pre><code>in = new ASCIIDataFile("wordsearch.txt");
  display = new ASCIIDisplayer();
  int numberWords = in.readInt();
  
  wordlist = new char[numberWords][];
  
  for (int i =0; i&lt;wordlist.length; i++){
    wordlist[i] = in.readLine().toUpperCase().toCharArray(); 
  }
  for(int i = 0;i&lt;wordlist.length; i++){
    display.writeLine(" ");
    for(int j = 0;j&lt;wordlist[i].length; j++){
      display.writeChar(wordlist[i][j]);
    }
  }
  //done wordlists
  
  int gridLength = in.readInt();
  int gridHeight = in.readInt();
  
  grid = new char[gridHeight][gridLength];
  
  for(int i = 0;i&lt;gridLength; i++){
    grid[i] = in.readLine().toCharArray();
  
  }
  </code></pre>
  
  <p>My problem in creating the algorithm to search though the 2d array and match it with a character in the wordlist.
  I am supposed to make different methods, for searching forwards, backwards and diagonal.
  I have been struggling for days just to do the forward search.</p>
  
  <p>I really how no idea about how to go about this problem, so far all I have is</p>
  
  <pre><code>for(int k = 0; k&lt;wordlist.length; k++){
    int p = 0;
    for(int row = 0;row&lt;gridLength; row++){
      for(int col = 0;col&lt;gridHeight; col++){
  
        while(p&lt;wordlist[k].length){
          if(grid[row][col] == wordlist[k][p]){
  
            //do something
  
          }
        }
      }
    }
  }    
  </code></pre>
  
  <p>}</p>
  
  <p>Any help or pointers would be greatly appreciated!</p>