title: First and second largest amount
body: <p>The problem is : </p>
  
  <blockquote>
    <p>Write a program that prompt the user to enter 5 numbers and find the
    two largest values among them. If the user enters number more than 100
    or less than – 100 the program should exit.</p>
  
  <pre><code>Hint: use break.
  </code></pre>
  </blockquote>
  
  <p>My code is :</p>
  
  <pre><code>import java.util.*;
  
  public class q2 {
      static Scanner scan = new Scanner (System.in);
      public static void main (String[] args ) {
  
          int num;
          int max=0;//define Maximum value and save it in variable max = 0;
          int secondMax=0;//define the second maximum value and save it in variable secondMax = 0;
  
          System.out.println("Please , Enter 5 numbers between 100 and -100 "); //promet user to enter 5 numbers with the condition
  
          for (int count=0 ; count&lt;5 ; count++) // start loop with (for) 
          {
              num = scan.nextInt();//user will enter number it will be repeated 5 times .
  
              if( num &gt; 100 || num&lt;-100) //iv the user enter a number less than -100 or geater than 100 program will quit from loop
              {
                  System.out.println("The number you have entered is less than -100 or greater than 100 ");//telling the user what he did
                  break;//End the loop if the condition ( num &gt; 100 || num&lt;-100) is true .
              }
              if(num&gt;max )//Another condition to find the maximum number
                  max = num;//if so , num will be saved in (max)
  
              if (num &gt;= secondMax &amp;&amp; num &lt; max)// A condition to find the second Maximum number
                  secondMax = num;//And it will be saved in (secondMax)
          }//End loop
          System.out.println("The largest value is " + max); //Print the largest number
          System.out.println("The second largest value is " + secondMax );//print the second largest number .
      }//End main
  
  }//End class
  </code></pre>
  
  <p>This is what my code outputs:</p>
  
  <pre><code>Please , Enter 5 numbers between 100 and -100 
  20
  30
  60
  20
  -10
  The largest value is 60
  The second largest value is 20
  </code></pre>
  
  <p>The second largest number is incorrect - 20, not 30. What did I do wrong?</p>