title: searching names in an array with a terminating character in java
body: <p>I am trying to write a method to search an array of names; with the ability to exit the search by entering an '*' either as the first char in the entered string or by itself... the logic seems to be be escaping me. im not sure what im doing wrong. the method should return the array element number if it is found, otherwise, -1. </p>
  
  <pre><code>public int searchNames(String [] names) throws IOException{
          Scanner keyboard = new Scanner(System.in);
          String line = "";
          while (line.charAt(0) != '*'){
              System.out.print("Enter a name to be searched, and an '*' to exit: ");
              line = keyboard.nextLine();
              for (int i = 0; i&lt;name.length; i++){
                  if (names[i].compareTo(line) == 0){return i;}
              }//end for loop
          }//end while loop
  
          return -1;
  
      }//end searchNames
  </code></pre>