title: how to program to find the largest 2 numbers and the smallest 2 numbers in the array in java
body: <p>finding largest and smallest in array is known, as i done in my below code
  but now how to print the <strong>two</strong> largest and <strong>two</strong> smallest elements from the array.</p>
  
  <pre><code>class twolargestsmallest 
  {
  public static void main(String args[]) {
  int a[]=new int[]{2,20,34,12,67};
  int smallest=a[0];
  int largest=a[0];
  for(int i=0;i&lt;a.length;i++){
  if(a[i]&lt;smallest){
  smallest=a[i]; }
  if(a[i]&gt;largest){ 
  largest=a[i]; }}
  System.out.println(smallest+" "+largest); }}
  </code></pre>