I am trying to search my java multidimensional array from top left to bottom right going in a vertical pattern. What is wrong with the code I have? -


I want to find my multi-dimensional array that has a 6x8 grid from top to bottom in vertical pattern for one word, But I can not understand what is wrong in my code Can someone tell me what I am doing?

  public static string search topobotom (four [] [] board, string word) {char [] letters = word.toCharArray (); For (int i = 0; i & lt; = board [i]. Length; i ++) {for (int j = 0; j & lt; = board.length; j ++) {boolean found = true ; (Int k = 0; k & lt; letters.length; k ++) {if ((i + k> board [j]. Length) [[letters [k]! = Board [j] [I + k])) {found = false; break; }} If (found) {return "string" + word + "row =" + + "col =" + j; }}} Return "string" + word + "did not get"; }    

  if ((i + k> board [j] Length] [(letter [of]! = Board [j] [i + of]) << code>  

If i + k is equal to board [ J]. Since the index goes from 0 to .length - 1 instead of & gt; & gt; = .

For the same reason, and ; requires the following : For (int i = 0; i & lt; = board [i]. Length; i ++) {will be changed for (for int j = 0; j & lt; = board Length; j ++ ) {

Because the maximum possible index will be length - 1 .

and this:

  For (int i = 0; i & lt; = board [i]. Length; i ++) {  

still looks incorrect, even after to and is changing. The i is considered to be an indicator of a column in the index array, but when you call the board [i] Then you are treating i . As a line index it will not make any problems for the 6x8 array, but it will be for an 8x6 array, because you want i to go from 0 to 7, but when I = 6 , board [6]. Length will be out of range. If you are certain that all rows have the same length, you should change it for

  (int i = 0; i    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -