title: How to input values to a scanner multiple times?
body: <p>I'm trying to make a small program to help with my homework. It needs to square a number that is input and then sum all the squares and display them. </p>
  
  <p>I came up with this but I have been getting errors.</p>
  
  <pre><code>import java.util.Scanner;
  
  
  public class Statistics {
  
  public static void main(String[] args) {
  
      int sum = 0;
      Scanner scan = new Scanner(System.in);
      Scanner input = new Scanner(System.in);
      System.out.println("\nHow many times?  ");
      int times = scan.nextInt();
      scan.close();
      for(int i = 0; i &lt; times; i++) {
          System.out.println("\nEnter the number to be squared: ");
          int squ = input.nextInt();
          System.out.println(squ + "\n\n");
          sum += squ;
      }
      input.close();
      System.out.println("\n\nSum = " + sum);
  }
  }
  </code></pre>
  
  <p>Here's the error I've been getting in the Eclipse console: </p>
  
  <pre><code>&gt;     Exception in thread "main" java.util.NoSuchElementException
  &gt;       at java.util.Scanner.throwFor(Unknown Source)
  &gt;       at java.util.Scanner.next(Unknown Source)
  &gt;       at java.util.Scanner.nextInt(Unknown Source)
  &gt;       at java.util.Scanner.nextInt(Unknown Source)
  &gt;       at Statistics.main(Statistics.java:16)
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>