title: optimizing an array sorting subroutine
body: <p>I have this code below , the purpose of this program is to generate 30 random numbers in an array and sort them from ascending to descending and showing the minimum value and maximum value once sorted , i want to optimize my sortit subroutine , the method i used sorts them by checking each number and moving them depending if they are bigger or smaller than the number next to them example:
  an array with these numbers : 78 19 90 8 23 
  my method goes to every number and starts to  move them so lets say so far the numbers 90 and 78 are in place making the array order like this  19 8 23 78 90 , so i dont want my program to go over the numbers 23 78 and 90 since they fall into place so how can i optimize this code so it wont go over the numbers that are already in place </p>
  
  <p>NB: i dont want already built functions like Array.sort()</p>
  
  <p>my code: </p>
  
  <pre><code>public class SortProg {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          int[] tab =new int[30];
          int i;
          for(i=0;i&lt; tab.length;i++) {
              tab[i]=(int)(Math.random()*1001);
              System.out.print(tab[i]+" ");
          }
  
          sortIt(tab);
          System.out.print("\nThe array after sorting: \n");
          for(i=0;i&lt; tab.length;i++) {
  
              System.out.print(tab[i]+" ");
          }
          System.out.print("\nThe smallest value is: "+tab[0]);
          System.out.print("\nThe biggest value is: "+tab[29]);
  }
      static void sortIt(int[]tab) {
          int i,j,temp;
          for(i=0;i&lt;tab.length-1;i++) {
              for(j=0;j&lt;tab.length-1;j++) {
                  if(tab[j]&gt;tab[j+1]) {
                      temp=tab[j];
                      tab[j]=tab[j+1];
                      tab[j+1]=temp;
                  }
              }
          }
      }
      }
  </code></pre>