title: Using a For loop to populate an array
body: <p>So I've been trying to get an array of values from a scanner and fill them in array. If the user enters 10 integer values or -1 the loop ends and the array stops filling in values. The following is the code I have written so far to do this:</p>
  
  <pre><code>// Input scanner and input controls
  Scanner scan = new Scanner(System.in);
  
  System.out.print("Please enter 10 integers \n");
  
  int maxnum = 10;
  boolean done = false;
  int count = 0;
  int[] arrays = new int[maxnum];
  
  
  // Store values in count array
  for (count = 0; (count &lt; maxnum &amp;&amp; !done); count++) {
      arrays[count] = scan.nextInt();
      if (arrays[count] == -1) {
          arrays[count] = 0;
          done = true;
      }
  
  }
  
  // print count values
  for (count = 0; (count &lt; maxnum); count++) {
      if (arrays[count] != 0) {
          System.out.println(arrays[count]);
      }
  
  }
  </code></pre>
  
  <p>What I have done so that -1 is not stored in the array is set the value of -1 to 0 and then tell my next loop not to print any values of 0. I know there has to be a better way to do this and I understand that I am still storing the zero values, but for the life of me I can not figure out how to prevent the loop from storing zero values in the array</p>