title: How to use a public static scanner in other methods? (nextLine());
body: <pre><code>import java.util.Scanner;
  
  public class mainClass{
  
      static public Scanner keyboard = new Scanner(System.in);
  
      public static void main (String [ ] args)
      {
          anotherMethod();
      }
  
      static public void anotherMethod()
      {
          String sentence;
          String answer;
  
          do{
              System.out.println("Lets read a sentence: ");
              String Sentence = keyboard.nextLine();
              System.out.println("The sentence read: " + sentence);
  
              System.out.println("Do you want to repeat?");
              answer = keyboard.next();
  
          } while (answer.equalsIgnoreCase("yes");
      }
  
  }
  </code></pre>
  
  <p>The result is that after the first run, the program displays <code>"Lets read a sentence:"</code> and also <code>"The sentence read: "</code> without letting me enter a sentence.. </p>
  
  <p>I would like to know the simple way of solving this problem.</p>