title: How to find numbers in an array that are greater than, less than, or equal to a value?
body: <p>I am trying to output the values that are less than five and the values that are greater than the average of all the values in the array . I can't figure out how to make it all work out and output the correct numbers. Can anyone help? </p>
  
  <p>Here's what I have, I am almost there I just don't know what I'm doing wrong.</p>
  
  <pre><code>{
     int[] numbers = {2, 4, 6, 8, 10, 12, 14, 16};
     int sum = 0;
     for (int x : numbers)
         sum += x;
  
  System.out.println("Numbers in order:"); 
     {
         for(int x = 0; x &lt; numbers.length; ++x) 
             System.out.println(numbers[x]);
     }
     System.out.println("Numbers in reverse order:");
     {
         for(int x = 0; x &lt; numbers.length; ++x) 
             System.out.println(numbers[x]);
     }
  
     System.out.println("The sum of all eight numbers is: " + sum);
     System.out.println("The lowest number is: " + numbers[0]);
     System.out.println("The highest number is: " + numbers[7]);
     System.out.println("The average of all eight numbers is: " + sum * 1.0 / 8);
     System.out.println("All numbers higher than the average are: ");
     {
         for(int x = 0; x &lt; numbers.length &amp;&amp; x &gt; 9;)
         {numbers[x] = x + 1;}
         int x = 0;
         System.out.println(numbers[x]);
     }
     System.out.println("Numbers less than 5: ");
  
     {
         for(int x = 0; x &lt; numbers.length &amp;&amp; x &gt; 5;)
         {numbers[x] = x + 1;}
         int x = 0;
         System.out.println(numbers[x]);
     }
  }  
  </code></pre>