title: I am getting wrong output in SelectionSort
body: <p>I was Supposed to get the output as </p>
  
  <pre><code>{-10,6,7,13,20,80,90,100} 
  </code></pre>
  
  <p>but I am getting the output as </p>
  
  <pre><code>{20,100,13,6,7,80,-10,90} 
  </code></pre>
  
  <p>in SelectionSort. Why am I getting this output? How can I solve this problem?</p>
  
  <pre><code>    public class x{
          public static void main(String args[]){
              int[] a= {20,13,6,7,80,-10,90,100};
              int i,j,c,largest;
              for(i=a.length-1;i&gt;0;i--){
                  largest=0;
                  for(j=1;j&lt;=(a.length-1);j++){
                      if(a[j]&gt;a[largest]){
                          largest=j;
                      }
  
                  }
                  swap(a,largest,i);
              }
              for(c=0;c&lt;a.length;c++)
                  System.out.println(a[c]);
          }
          public static void swap(int[] arr, int a, int b){
              int temp;
              if(a==b){
                  return;
              }
              temp=arr[a];
              arr[a]=arr[b];
              arr[b]=temp;
          }
      }
  </code></pre>