title: Display Second Largest no in Array in Java
body: <p>Hi all I want to find out second Largest no in Array accept negative numbers. I have used following code and this display second largest no of only positive no.So please suggest me how to do this.</p>
  
  <pre><code>class ArrayExample {
      public static void main(String[] args) {
          int secondlargest = 0;
          int largest = 0;
          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])
                  secondlargest = arr[i];
          }
          System.out.println("Second Largest number is: " + secondlargest);
      }
  }
  </code></pre>