title: Array input class throws up the exception error
body: <p>I am very new to Java. I am trying this code. I want to input a series of integers into an array and get them printed both forwards and backwards.  But I get the error</p>
  <p>I am getting the following error</p>
  <pre><code>    Size of array?
      Exception in thread &quot;main&quot; java.util.NoSuchElementException
      at java.base/java.util.Scanner.throwFor(Scanner.java:937)
      at java.base/java.util.Scanner.next(Scanner.java:1594)
      at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
      at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
      at LoadIntegerArray.getInteger(LoadIntegerArray.java:15)
      at LoadIntegerArray.main(LoadIntegerArray.java:25)
  </code></pre>
  <p>The code I am using is :</p>
  <pre><code>   import java.util.Scanner;
  
     public class LoadIntegerArray
      {
      static int getInteger(Scanner sc, String prompt)
      {
          System.out.print( prompt);
          return sc.nextInt();
      }   
      static void getIntegers(Scanner sc, int [] arr)
        {
        for (int i = 0; i &lt; arr.length; i++)
               arr[i] = getInteger(sc, &quot;Element &quot; + i + &quot;: &quot;);
          }
   public static void main(String args[])
     { 
      Scanner keyboard = new Scanner(System.in);
      int extent = getInteger(keyboard, &quot;Size of array? &quot;);
      int[] testArray = new int[extent];
      getIntegers(keyboard, testArray);
      System.out.println(&quot;\nForwards: &quot;);
          for (int i = 0; i &lt; testArray.length; i++)
              System.out.println(&quot;testArray[&quot; +i+ &quot;]: &quot; + testArray[i]);
              System.out.println(&quot;\nBackwards: &quot;);
          for (int i = testArray.length - 1; i &gt;= 0; i--)
              System.out.println(&quot;testArray[&quot; +i+ &quot;]: &quot; + testArray[i]);
              System.out.println(&quot;\nFor-each: &quot;);
          for (int value: testArray)
              System.out.println(value);
     }
     }
  </code></pre>