title: Exception in thread "main" java.util.NoSuchElementException on ideone
body: <p>This is my first code with java .when I tested it on Ideone. It showed:</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 Hw2_p4.main(Main.java:22)
  </code></pre>
  
  <p>I searched for answers but I didn't get the problem cause or how to fix it.
  the code runs on eclipse normally</p>
  
  <p>Here is the code</p>
  
  <pre><code>import java.util.Scanner;
  
  class Hw2_p4 {
  
      static void swap(String[] A, int a, int b) {
          String temp = A[a];
          A[a] = A[b];
          A[b] = temp;
      }
  
      public static void main(String[] args) {
  
          Scanner sc = new Scanner(System.in);
  
          int n = sc.nextInt(), m = sc.nextInt();
          int i, j, k, l, counter = 0;
  
          String[] name = new String[16];
          String[][] notalong = new String[120][2];
          String[] temp = new String[120];
          boolean[][] A = new boolean[120][2];
  
          for (i = 0; i &lt; n; i++) {
              name[i] = sc.next();
          }
  
          for (i = 0; i &lt; m; i++) {
              for (j = 0; j &lt; 2; j++) {
                  notalong[i][j] = sc.next();
              }
          }
  
          int flag = 0;
  
          for (i = 0; i &lt; m; i++) {
              for (j = 0; j &lt; 2; j++) {
                  flag = 0;
                  for (k = i + 1; k &lt; m; k++) {
                      for (l = 0; l &lt; 2; l++) {
                          if (notalong[i][j].compareToIgnoreCase(notalong[k][l]) == 0 &amp;&amp; A[i][j] == false &amp;&amp; A[k][l] == false) {
                              A[k][l] = true;
                              flag = 1;
                          }
                      }
                  }
  
                  if (flag == 1) {
                      A[i][j] = true;
                      counter++;
                  } else if (flag == 0 &amp;&amp; A[i][0] == false &amp;&amp; A[i][1] == false) {
                      A[i][j] = true;
                      counter++;
                  }
              }
  
          }
  
          System.out.println(n - counter);
          int x = 0;
  
          for (i = 0; i &lt; m; i++) {
              for (j = 0; j &lt; 2; j++) {
                  if (A[i][j] == false) {
                      temp[x++] = notalong[i][j];
                      A[i][j] = true;
  
                      for (k = i + 1; k &lt; m; k++) {
                          for (l = 0; l &lt; 2; l++) {
                              if (notalong[i][j].compareToIgnoreCase(notalong[k][l]) == 0 &amp;&amp; A[k][l] == false) {
                                  A[k][l] = true;
                              }
                          }
                      }
                  }
              }
          }
  
          //compare not along with names
          int found = 1;
  
          for (i = 0; i &lt; n; i++) {
              found = 0;
              for (j = 0; j &lt; m; j++) {
                  for (k = 0; k &lt; 2; k++) {
                      if (name[i].compareToIgnoreCase(notalong[j][k]) == 0) {
                          found = 1;
                      }
                  }
              }
  
              if (found == 0) {
                  temp[x++] = name[i];
              }
          }
  
          //sorting lexicographically
          boolean swapp = true;
          for (i = 0; i &lt; x &amp;&amp; swapp; i++) {
              swapp = false;
              for (j = 0; j &lt; x - i - 1; j++) {
                  if (temp[j].compareToIgnoreCase(temp[j + 1]) &gt; 0) {
                      swap(temp, j, j + 1);
                      swapp = true;
                  }
              }
          }
  
          for (i = 0; i &lt; x; i++) {
              System.out.println(temp[i]);
          }
      }
  }
  </code></pre>