title: how to fix cannot resolve symbol and variable never used, errors
body: <p>I am new to java and this is my first program, I'm very confused with these errors and have looked everywhere for the answer. please help!</p>
  <pre><code>
  import java.util.Scanner;
  
  public class Main {
  
      public static void main(String[] args) {
  
          Scanner myObj = new Scanner(System.in);
  
          System.out.println(&quot;Enter first number&quot;);
          String str1 = myObj.nextLine();
  
          System.out.println(&quot;Enter Operator&quot;);
          String op = myObj.nextLine();
  
          System.out.println(&quot;Enter second number&quot;);
          String str2 = myObj.nextLine();
  
          int num1 = Integer.parseInt(str1);
          int num2 = Integer.parseInt(str2);
  
          if (op.equals(&quot;+&quot;)) {
              int ans = (num1 + num2);
          } else if (op.equals(&quot;-&quot;)){
              int ans = (num1 - num2);
          }
          System.out.println(num1 + &quot; &quot; + op + &quot; &quot; + num2 + &quot; = &quot; + ans);
      }
  }
  </code></pre>
  <p>Then it gives me these errors, I'm using IntelliJ idea</p>
  <pre><code>Cannot resolve symbol 'ans'
  Variable 'ans' is never used
  Variable 'ans' is never used
  </code></pre>