title: What is the purpose of having ".nextDouble" after storing an input?
body: <p>After programming in C++ for a few months, and getting to an intermediate level, I decided to start learning Java. I'm having some trouble wrapping my head around how the scanner variable works. In C++, "cin>>" was very straightforward in the fact that it would store whatever the input was, into a previously declared variable. However, in Java a variable itself is a scanner? How does that work? Also, what is the purpose of having ".nextDouble" after telling the scanner where to store the variable? I learned it from a tutorial, and here's my code below. </p>
  
  <pre><code>import java.util.Scanner;
  class calculator {
   public static void main(String args[]) {
       Scanner var = new Scanner(System.in);
       double fnum, snum, answer;
       System.out.println("Enter first number: ");
       fnum = var.nextDouble();
       System.out.println("Enter second number: ");
       snum = var.nextDouble();
       answer = fnum+snum;
       System.out.println(answer);
  
  
   }
       }
  </code></pre>