title: Getting the average value and the sum of all values in a user-inputed array?
body: <p>I need to write an application which can store 10 000 user-inputed values, in an array, and that can return the sum of all values and the average of all values. The input must be stopped if the user writes the number "0". There are some conditions that need to be fulfilled:</p>
  
  <ol>
  <li>The values needs to be stored in an array</li>
  <li>The users input data must be inside a while-loop</li>
  <li>The analysis (the math, so to speak), must be done after the user-input is done.</li>
  <li>The application is not allowed to loop any empty elements.</li>
  </ol>
  
  <p>This is a extra assignment I got in class today.</p>
  
  <p>So far I've written this:</p>
  
  <pre><code>import java.util.Scanner;
  
      public class Ovning_54 {
          public static void main(String[] args) {
              Scanner input = new Scanner(System.in);
              int[] list;
              list = new int[10000];
              int sum = 0;
              int avr = 0;
              int x = 0;
              int number;
  
              System.out.print("Add number " + (x + 1) + ": ");
              number = input.nextInt();
  
              while (x &lt;= list.length &amp;&amp; (number != 0 || x == 0)) {
                   list[x] = number;
                   x++;
                   System.out.print("Add number " + (x + 1) + ": ");
                   number = input.nextInt();
              }
  
              for (int i = 0; i &lt; x; i++) {
                   sum += list[i];
                   avr = sum / x;
              }
  
              System.out.println("The sum of all values are: " + sum);
              System.out.println("The average value of the numbers are: " + avr);
            }
  
      }    
  </code></pre>
  
  <p>I think I've solved it! Seems to be running correctly and I get no error messages what so ever. I'm still wondering if that violates condition #1. If not, is there a way around it?</p>