title: Utilizing a Scanner inside a method
body: <p>I'm new to programming, so I apologize if there is a very simple answer to this, but I cannot seem to find anything that actually.  I am using a scanner object for user input in a guess your number game.  The scanner is declared in my main method, and will be used in a single other method (but that method will be called all over the place).</p>
  
  <p>I've tried declaring it as static, but eclipse has a fit over that and won't run.</p>
  
  <pre><code> public static void main(String[] args) {
      int selection = 0;
      Scanner dataIn = new Scanner(System.in);
      Random generator = new Random();
      boolean willContinue = true;
  
      while (willContinue)
      {
          selection = GameList();
  
          switch (selection){
          case 1: willContinue = GuessNumber(); break;
          case 2: willContinue = GuessYourNumber(); break;
          case 3: willContinue = GuessCard(); break;
          case 4: willContinue = false; break;
          }
  
      }
  
  
  
  }
  
  public static int DataTest(int selectionBound){
      while (!dataIn.hasNextInt())
      {
          System.out.println("Please enter a valid value");
          dataIn.nextLine();
      }
  
      int userSelection = dataIn.nextInt;
      while (userSelection &gt; selectionBound || userSelection &lt; 1)
      { 
          System.out.println("Please enter a valid value from 1 to " + selectionBound);
          userSelection = dataIn.nextInt;
      }
  
  
      return userSelection;
  }
  </code></pre>