0
 //searching a word
    String search;
    System.out.println("Please enter a word you have found:");//word found from the 2d array grid
    search = kb.nextLine();
    
    System.out.println("First character of the word: "+search.charAt(0));//testing the split string
    System.out.println("Length of the word: "+search.length());//length for string
    
    for(int i=0; i<search.length(); i++){
      System.out.println(search.charAt(i));}
    
    int [] answerCheck = new int [search.length()];
    
    String searchLetter;
    String tableLetter;
    
    for (int row=0; row<table.length; row++){
      System.out.println("Loop "+row);
      searchLetter = String.valueOf(search.charAt(row));//convert char to string
      if (row>answerCheck.length){
        break;}//closes the for-loop

      for(int col=0; col<table[row].length; col++){
        tableLetter = table[row][col];
        if(tableLetter.equals(letter));{
        answerCheck[row] = 1;
        System.out.println(table[row][col]+" = "+letter);}}}

How can i find the same letter of a char string in a 2d array?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Your question is not very clear. – shmosel Mar 08 '22 at 02:32
  • 1
    `if(tableLetter.equals(letter));{` that is an **unfortunate** semicolon. That makes an `if` with no body. The braces open a semantically independent block. You should indent your code properly. That would have helped. – Elliott Frisch Mar 08 '22 at 02:32
  • thank you for helping me, i did see better progress with eliminating that error, however for some reason i am still getting a java.lang.StringIndexOutOfBoundsException: String index out of range: 4 at java.lang.String.charAt(Unknown Source) – Ilyas Hirji Mar 08 '22 at 02:37
  • It's OK to do things "the hard way" in order to learn, but there are better ways of searching strings. Can you back up a few steps and tell us what you are trying to accomplish? And post your full code, the bit you have provided doesn't really clarify the question. – markspace Mar 08 '22 at 02:39
  • np ill send the full code – Ilyas Hirji Mar 08 '22 at 02:50
  • srry this is my first time using this website so im not sure how i can send the full code – Ilyas Hirji Mar 08 '22 at 02:53

0 Answers0