title: Scanner for array's and checking for negatives
body: <p>I'm trying to write a program that scans in values from the console and stores them in the array. I'm trying to allow the user to specify the length of the array using the scanner. An array length as you know, can only be positive, so I'm trying to check, here's what I have so far that in my mind should be working.</p>
  
  <pre><code>    int[] array; 
  int index = 0;
  
  max = new Scanner(System.in);
  
  System.out.println("How long is your array?");
  
  while (!max.hasNextInt() || max.nextInt() &lt;=0 ) 
  {
    System.out.println("Arrays aren't negative, unless your's is " +
                  "smaller then physically posible, try again");
    max.next(); 
  }
  maxSize = max.nextInt();
  
  
  array = new int[maxSize];
  
  System.out.println("Enter up to " + maxSize + " integers");
  
  input = new Scanner(System.in);
  
  
  while(input.hasNextInt())
  {
    array[index] = input.nextInt();
    index++;
  }
  
  return array;
  </code></pre>
  
  <p>It's working somewhat, here's the output
  How long is your array?</p>
  
  <p>-2</p>
  
  <p>Arrays aren't negative, unless your's is smaller then physically posible, try again</p>
  
  <p>-3</p>
  
  <p>-4</p>
  
  <p>Arrays aren't negative, unless your's is smaller then physically posible, try again</p>
  
  <p>2</p>
  
  <p>3</p>
  
  <p>4</p>
  
  <p>Enter up to 4 integers</p>
  
  <p>Any help is appreciated, and also it does not seem to be storing the array at all so any help with that is appreciated however I just while testing the max size so I'm going to try and figure it out. I'm thinking it may be from using two scanners now that I'm looking at my code, this is my first experience with scanners. Thanks in advance!</p>