title: How do I convert scanner input into an integer?
body: <p>In Java, how, if possible, can I convert numerical scanner input (such as 2 or 87) into an integer variable? What I'm using now yields the error message:</p>
  
  <pre><code>    Exception in thread "main" java.lang.NumberFormatException: null
      at java.lang.Integer.parseInt(Unknown Source)
      at java.lang.Integer.valueOf(Unknown Source)
      at diDecryption.Didecryption.main(Didecryption.java:226)
  </code></pre>
  
  <p>And this is the code I'm using to do it (pieced together, it's part of a much larger program):</p>
  
  <pre><code>    System.out.println("Enter first number");
      Scanner sc=new Scanner(System.in); 
      String name=sc.next();
      int result = Integer.valueOf(name);
      if (result / 2 == 1){
      System.out.println("a");
  </code></pre>
  
  <p>The purpose of the program is to decode an encrypted message. The input is numerical, and if I remove the string to int converter, the division does not work. How do I fix this?</p>