title: Find third largest no in Java
body: <p>I'm little confused with this simple program.I have to find third largest no in array.I have done some code but getting only second largest no problem in third largest no so please suggest me what is wrong with this solution:</p>
  
  <pre><code>class ArrayExample {
      public static void main(String[] args) {
          int secondlargest = Integer.MIN_VALUE;
          int thirdlargest = Integer.MIN_VALUE;
          int largest = Integer.MIN_VALUE;
          Scanner input = new Scanner(System.in);
          System.out.println("Enter array values: ");
          int arr[] = new int[5];
          for (int i = 0; i &lt; arr.length; i++) {
              arr[i] = input.nextInt();
              if (largest &lt; arr[i]) {
                  secondlargest = largest;
                  largest = arr[i];
              }
              if (secondlargest &lt; arr[i] &amp;&amp; largest != arr[i]) {
                  thirdlargest = secondlargest;
                  secondlargest = arr[i];
                  if (thirdlargest &lt; arr[i] &amp;&amp; secondlargest != arr[i])
                      thirdlargest = arr[i];
              }
  
          }
          System.out.println("Second Largest number is: " + secondlargest
                  + "\nThird largest number is=====" + thirdlargest);
      }
  }
  </code></pre>