title: Reading multiple numbers on a single line with Scanner
body: <p>I need to read multiple numbers (don't know how many numbers I'm going to read, but I know they are at most six numbers) from a single line using a Scanner. I tried something found on the net but I couldn't find a solution. The reading stops when the user writes -1. Here's what I wrote up to now:</p>
  
  <pre><code>Scanner read = new Scanner(System.in);
  int i;
  float buffer[] = new float[6];
  
  while (read.nextInt() != -1) {
              if (read.hasNextInt()) {
                  buffer[i] = read.nextInt();
                  i++;
              } else {
                  break;
              }
          }
  </code></pre>
  
  <p>When I try to run this, I get a <code>NoSuchElementException</code>, but I don't understand why. What's wrong with this code? How can I correct this? Thanks in advance.</p>