title: Largest and smallest integer - exercise from Deitel's Java book
body: <p>Exercise from Deitel's "Java How To Program" 10th edition:</p>
  
  <blockquote>
    <p>2.24 (Largest and Smallest Integers) Write an application that reads five integers and determines and prints the largest and smallest
    integers in the group. Use only the programming techniques you learned
    in this chapter.</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>// Ex. 2.24: LargestAndSmallestIntegers.java
  // Obtain five numbers from the user, display largest and smallest from the group.
  import java.util.Scanner;
  
  public class LargestAndSmallestIntegers
  {
      public static void main(String[] args)
      {
          Scanner input = new Scanner(System.in);
          int number1, 
              number2, 
              number3, 
              number4, 
              number5,
              largest,
              smallest;
  
          System.out.print("Enter first integer: ");
          number1 = input.nextInt();
  
          System.out.print("Enter second integer: ");
          number2 = input.nextInt();
  
          System.out.print("Enter third integer: ");
          number3 = input.nextInt();
  
          System.out.print("Enter fourth integer: ");
          number4 = input.nextInt();
  
          System.out.print("Enter fifth integer: ");
          number5 = input.nextInt();
  
          largest = number1;
          smallest = number1;
  
          if (number2 &gt; largest)
              largest = number2;
          if (number3 &gt; largest)
              largest = number3;
          if (number4 &gt; largest)
              largest = number4;
          if (number5 &gt; largest)
              largest = number5;
  
          if (number2 &lt; smallest)
              largest = number2;
          if (number3 &lt; smallest)
              largest = number3;
          if (number4 &lt; smallest)
              largest = number4;
          if (number5 &lt; smallest)
              largest = number5;
  
          System.out.printf("Largest of five integers is %d, and smallest is %d%n", largest, smallest);
      }
  }
  </code></pre>
  
  <p>What did I do wrong? Why it doesn't pick-up the largest and smallest integers?</p>