title: In Java, I am doing a project, and I can compile my code in Eclipse, but anywhere else I get a runtime exception
body: <pre><code>import java.util.*;
  import java.io.*;
  
  public class Tester 
  {
  
      public static void main(String[] args) 
      {
  
          Scanner reader = new Scanner(System.in);
          int cases = reader.nextInt();
          for(int i = 0; i &lt; cases; i++)
          {
              int len = reader.nextInt();
              int ants = reader.nextInt();
              int[] distance = new int[ants];
              for(int j = 0; j &lt; ants; j++)
              {
                  distance[j] = reader.nextInt();
  
              }
              Arrays.sort(distance);
              int longest = len - distance[0];
              int mid = (len / 2);
              int val2 = 0;
              int val1 = 0;
              for(int k = 0; k &lt; distance.length; k++)
              {
                  if((mid &gt; distance[k]) &amp;&amp; (mid &lt; distance[k + 1]))
                  {
                      val1 = distance[k] ;
                      val2 = distance[k + 1];
                  }
              }
              int shortest;
              if(val1 &gt; len - val2)
                  shortest = val1;
              else
                  shortest = len - val2;
  
              if(i + 1 != cases)
                  System.out.println(shortest + " " + longest);
              else
                  System.out.print(shortest + " " + longest);
  
  
          }
  
          reader.close();
  
      }
  
  }
  </code></pre>
  
  <p>Any help is greatly appreciated. I don't understand why it works in eclipse, but not anywhere else. It seems by the errors that it is something to do with scanner as the error I get is:</p>
  
  <pre><code>Exception in thread "main" java.util.NoSuchElementException
      at java.util.Scanner.throwFor(Scanner.java:862)
      at java.util.Scanner.next(Scanner.java:1485)
      at java.util.Scanner.nextInt(Scanner.java:2117)
      at java.util.Scanner.nextInt(Scanner.java:2076)
      at Tester.main(Tester.java:12)
  </code></pre>
  
  <p>Any help I receive is greatly appreciated. I am quite new to programming and have nobody to receive help from.
  The input is:</p>
  
  <p>2
  10 3
  2 6 7
  214 7
  11 12 7 13
  176 23 191</p>