title: Sorting an Array of int using BubbleSort
body: <p>Why is my printed out Array not sorted in the below code?</p>
  
  <pre><code>public class BubbleSort {
  
     public void sortArray(int[] x) {//go through the array and sort from smallest to highest
        for(int i=1; i&lt;x.length; i++) {
           int temp=0;
           if(x[i-1] &gt; x[i]) {
              temp = x[i-1];
              x[i-1] = x[i];
              x[i] = temp;
           }
        }
     }
  
     public void printArray(int[] x) {
        for(int i=0; i&lt;x.length; i++)
          System.out.print(x[i] + " ");
     }
  
     public static void main(String[] args) {
        // TestBubbleSort
        BubbleSort b = new BubbleSort();
        int[] num = {5,4,3,2,1};
        b.sortArray(num);
        b.printArray(num);   
     }
  }
  </code></pre>