title: Closing a Scanner, Unreachable Code?
body: <p>I searched stackoverflow pretty thoroughly and tried a few suggestions from other questions, but none solved my issue. I can't see ANY reason why this shouldn't work. Normally I would say forget it and let the garbage collector deal with it but my instructor requires the scanner be closed every time. Yes, this is a homework assignment.</p>
  
  <p>Everything in the following code works fine, but when I try to close the scanner it gives me an unreachable code error in Eclipse. I've attempted to open the scanner in different places, but that causes runtime errors since it needs the scanner every time the logic runs. When I put input.close(); at the very end of the main method (which works fine in other assignments I've completed), but something isn't working right here. Here is and slightly abridged version of the code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class stateBird {
  
  public static int stateInformation(String stateBirdFlower[][],String state)
     {
         int arrayPos = -1;
         boolean found = false;
         for (int index = 0; index &lt; stateBirdFlower.length &amp;&amp; !found; index++)
         {
             if(stateBirdFlower[index][0].equalsIgnoreCase(state))
                 arrayPos=index;            
         }
         return arrayPos;
     }
  
  
  public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
  
  
          String[][] stateInformation = new String[][] {
              {"Alabama", "Yellowhammer", "Camelia"},
              {"Alaska", "Willow Ptarmigan", "Forget-Me-Not"},
              {"Arizona", "Cactus Wren", "Saguaro Cactus Blossom"}
          };
  
         while(true) {
  
              System.out.print("Enter the full name of the state you would like to view or type 'none' if you would like to quit: ");
  
              String stateName = input.nextLine();
  
  
              if(stateName.equalsIgnoreCase("None")) {
                  System.exit(0);
              }
              else {
                  int position = stateInformation(stateInformation, stateName);
                  if(position != -1) {
  
                      System.out.println("\n" + stateName + "'s " + "Bird is: " + stateInformation[position][1]);
                      System.out.println(stateName + "'s " + "Flower is: " + stateInformation[position][2] + "\n" );                 
  
                  }
                  else {
                      System.out.println("Invalid State Entered");
                  }              
  
  
  
              }   //End if (stateName...) statement  
  
         } //End while(true) statement
  
      input.close();   
      }//End main method
  
  }//End class stateBird
  </code></pre>
  
  <p>As I stated above, everything in the code works fine, so what is going on with my input.close()? It is opened at the very beginning of the main method, and closed at the very end, that has worked every time before for me, what's different here?</p>
  
  <p>Thanks!</p>