title: difference between these two bubble sort implementations
body: <p>I have two implementations of bubble sort, but one of them works fine and other one does not can anybody explain me what is the difference in these two</p>
  
  <p>first one this works fine</p>
  
  <pre><code>private static int[] sortBuble(int[] a) {
          boolean swapped = true;
          for (int i = 0; i &lt; a.length &amp;&amp; swapped; i++) {
              swapped = false;
              System.out.println("number of iteration" + i);
  
              for (int j = 1; j &lt; a.length; j++) {
  
                  if (a[j - 1] &gt; a[j]) {
                      int temp = a[j - 1];
                      a[j - 1] = a[j];
                      a[j] = temp;
                      swapped = true;
                  }
              }
          }
  
          return a;
      }
  </code></pre>
  
  <p>Second one this does not work, but they look more or less same</p>
  
  <pre><code>private static int[] sortBuble1(int[] a) {
          boolean swapped = true;
          for (int i = 0; i &lt; a.length &amp;&amp; swapped; i++) {
              swapped = false;
              System.out.println("number of iteration" + i);
  
              for (int j = i + 1; j &lt; a.length; j++) {
  
                  if (a[i] &gt; a[j]) {
                      int temp = a[i];
                      a[i] = a[j];
                      a[j] = temp;
                      swapped = true;
                  }
              }
          }
  
          return a;
      }
  </code></pre>