title: Read a list of nonnegative integers and to display the largest integer, the smallest integer and the average of all the integers
body: <p>I have encountered some problems with the calculating of largest and smallest number... If the first number I entered is a larger number than the 2nd number input, it will not record the 1st number into the largest... </p>
  
  <p>Take a look at the output, it will help elaborate better..
  <a href="http://i.stack.imgur.com/rge84.jpg" rel="nofollow">Calculation Error..</a> &amp; 
  <a href="http://i.stack.imgur.com/Nl2y7.jpg" rel="nofollow">1st input problem..</a>
  Codes below!</p>
  
  <pre><code>public static void main(String[] args) {
  
      int smallest = Integer.MAX_VALUE;
      int largest = 0;
      int number;
      double totalAvg = 0;
      double totalSum = 0;
      int count = 0;
  
      Scanner kb = new Scanner(System.in);
  
      System.out.println("Enter few integers (Enter negative numbers to end input) :");
      while (true) { //LOOP till user enter "-1"
          number = kb.nextInt();
  
          //Condition for the loop to break
          if (number &lt;= -1) {
              System.out.println("End Of Input");
              break;
          } else {
              count = count + 1;
          }
  
          if (number &lt; smallest) { //Problem 1 : If 1st input num is bigger than 2nd input num,
              smallest = number;  // largest num will not be recorded..
          } else {
              largest = number;
          }
  
          totalSum = totalSum + number;
          totalAvg = (totalSum / count);
  
      }
  
      System.out.println("The smallest number you have entered is : " + smallest);
      System.out.println("The largest number you have entered is : " + largest);
      System.out.println("The total sum is : " + totalSum);
      System.out.println("The total average is : " + totalAvg);
      System.out.println("Count : " + count);
  } // PSVM
  </code></pre>