title: Java Program: finding smallest and largest number of 3 numbers in an array
body: <p>The code below works fine for the largest value but for the smallest value it is displaying: <em>smallest number is 0</em> for any 3 values I input. Would greatly appreciate any help.</p>
  
  <pre><code>import java.util.Scanner;
  
  class MyClass{
  
  
          public static void main(String[] args) {
              // declare and create array object
              // declare smallest and largest int variables 
              int[] numbers;
              numbers = new int[3];
              int smallest = numbers[0], largest = numbers[0];
  
              // create Scanner object
              Scanner input = new Scanner(System.in);
  
              // prompt user 
              System.out.print("Please enter 3 numbers: \n");
              // use for loop to obtain user input
              for (int counter = 0; counter &lt; numbers.length; counter++) {
                  numbers[counter] = input.nextInt();
              } // end obtaining input
  
              // for loop to find largest and smallest values
              for (int i=0 ;i&lt; numbers.length; i++) {
                  if (numbers[i] &lt; smallest) {
                      smallest = numbers[i];
                  } // end finding smallest
                  if (numbers[i] &gt; largest) {
                      largest = numbers[i];
                  } // end finding largest number       
  
              }
  
              System.out.println("largest number is "+largest);
              System.out.println("smallest number is "+smallest);
  
          }   
  
  }
  </code></pre>