title: Skipping scanner class inputs
body: <p>I am trying to create a calculator using java, it works pretty well the first time that it is used, however once it loops back to asking for the operator, it prints the <code>&quot;Enter operator (+, -, *, /):&quot;</code> and immediately prints <code>&quot;Enter # 1&quot;</code> ultimately skipping the ability to input the operator. I don' understand why that happens nor how to fix it, any ideas?</p>
  <pre><code>import java.util.Objects;
  import java.util.Scanner;
  
  public class Main {
      public static void main(String[] args) {
  
  
          final String check = &quot;+-*/&quot;;
          Scanner sc = new Scanner(System.in);
          String op = &quot;&quot;;
  
          do
          {
              System.out.println(&quot;Enter operator (+, -, *, /):&quot;);
              op = sc.nextLine();
              if (check.contains(op))
              {
  
                  System.out.println(&quot;Enter # 1&quot;);
                  double num1 = sc.nextDouble();
  
                  System.out.println(&quot;Enter # 2&quot;);
                  double num2 = sc.nextDouble();
  
                  if (Objects.equals(op, &quot;+&quot;)) {
  
                      double ans = num1 + num2;
                      System.out.println(&quot;= &quot; + ans);
                  }
                  if (Objects.equals(op, &quot;-&quot;)) {
                      double ans = num1 - num2;
                      System.out.println(&quot;= &quot; + ans);
                  }
                  if (Objects.equals(op, &quot;*&quot;)) {
                      double ans = num1 * num2;
                      System.out.println(&quot;= &quot; + ans);
                  }
  
                  if (Objects.equals(op, &quot;/&quot;)){
                      double ans = num1 / num2;
                      System.out.println(&quot;= &quot; + ans);
                  }
  
              }else{
                  System.out.println(&quot;Please enter a valid operator.&quot;);
              }
          }while(true);
      }
  }
  </code></pre>