title: Compare user input against a multidimensional array element in Java using loops
body: <p>I am still newbie to Java so I am having a problem with my program. I am trying to write a small program showing table booking system, it shows all available tables then takes the user input and compares it against a multidimensional array that holds all the table numbers then assign that value with &quot;[XX]&quot;<br />
  so if the user tries to book the same number again they won't be able to.</p>
  <p>I can't seem to find a way to compare the user input against the array or to assign the new value &quot;[XX]&quot;.</p>
  <p>The code is below:</p>
  <pre><code>import java.util.Scanner;
  import java.util.ListIterator;
  import java.util.Random; 
  
  
  
  
  
  
  
  public class exercises {
      
      public static void compare(String tableEnt, String tables [][])
      {
          for(int k=0; k&lt;tables.length; k++)
          {
              if(tableEnt.equals(tables[k]))
                  System.out.println(&quot;The number has been entered before.&quot;);
          }
      }
      
      
      // multidimensional array to display all table numbers. 
      static String tables [][] = {   
              {&quot; [01] &quot; , &quot; [02] &quot; , &quot; [03] &quot; , &quot; [04]  &quot; , &quot; [05] &quot; , &quot; [06] &quot; , &quot; [07]  &quot;},
              {&quot; [08] &quot; , &quot; [09] &quot; , &quot; [10] &quot; , &quot; [11]  &quot; , &quot; [12] &quot; , &quot; [13] &quot; , &quot; [14]  &quot; + &quot; \n &quot;},
  
              {&quot; [15] &quot; , &quot; [16] &quot; , &quot; [17] &quot; , &quot; [18]  &quot; , &quot; [19] &quot; , &quot; [20] &quot; , &quot; [21]  &quot;},
              {&quot; [22] &quot; , &quot; [23] &quot; , &quot; [24] &quot; , &quot; [25]  &quot; , &quot; [26] &quot; , &quot; [27] &quot; , &quot; [28]  &quot; + &quot; \n &quot;},
  
              {&quot; [29] &quot; , &quot; [30] &quot; , &quot; [31] &quot; , &quot; [32]  &quot; , &quot; [33] &quot; , &quot; [34] &quot; , &quot; [35]  &quot;},
              {&quot; [36] &quot; , &quot; [37] &quot; , &quot; [38] &quot; , &quot; [39]  &quot; , &quot; [40] &quot; , &quot; [41] &quot; , &quot; [42]  &quot;}};
      
      
      // A method for displaying all tables
              public static void displayTable() {
                      
                      for(int i =0; i&lt;6; i++) {
                          for(int j=0; j&lt;7; j++) {
                              System.out.print(tables[i][j]);
                          }
                          System.out.println();   
                      }
              } 
      
       
  
          
          public static void main(String[] args) {
              //Variable declarations: 
              
              boolean found = false;
              
              
              
              int min = 1;
              int max = 42;
           
              
              String name;
              int newTable = 1;
              //int tableID;
              
          // boolean answer;
              
              //Welcome message to the customer
              System.out.println(&quot;Welcome to the booking system &gt; &quot;);
              System.out.println();
              
              System.out.println(&quot;Please enter your full-name&gt; &quot;);
              Scanner input1 = new Scanner(System.in);
              Scanner input2 = new Scanner(System.in);
              
              name = input1.next();
          
              
                  while (true) {
                  
                  displayTable();
                  System.out.println();
              
              System.out.println(&quot;Thank you, &quot; + name );  
              
              
              
                  
              
              
                  
              for (int k = 0; k &lt; tables.length; k++) {
                  
                  System.out.println(&quot;Enter a table number&quot;);
                  int tableID = input2.nextInt();
                  String tableString = Integer.toString(tableID);
                  
                  
                  if(tableString.equals(tables[k])) {
                      System.out.println(&quot;This table is booked.&quot;);
                  }
                  
                  else { System.out.println(&quot;Your allocated table is: &quot;);
                    int random_int = (int)(Math.random() * (max - min + 1) + min);
                    System.out.println(random_int);
                      
                  
                  
                  }
                  
              }
              
                  
              
              
              
              
                  }   
                  
                  
               
              
          
  
  
   
  
              
  
  
   
       
       
        }
           
  }
          
  
    
       
  </code></pre>