title: For loop stopping prematurely
body: <p>I'm trying to solve problem #299 - Train Swapping in website UVa Online judge. The code I have works fine for independent test cases. However, when I use the sample input they provide, my program omits one of the test cases, the last one to be more specific:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.util.Scanner;
  public class Tester {
    void problem(){
      Scanner imput = new Scanner(System.in);
      int numT =imput.nextInt();
      int numL, aux, swaps=0;
      int [] train = new int [50];
  
      for (int i =0; i&lt;numT; i++) {
        numL = imput.nextInt();
  
        for (int m =0; m&lt; numL; m++) {
          train[m]=imput.nextInt();
        }
  
        for (int j=0; j&lt;numL; j++) {
          if (train[j]&gt;train[j+1]) {
            for (int k =j; k&lt;numL-1;k++) {
              aux = train[k];
              train[k]=train[k+1];
              train[k+1]=aux;
              swaps++;
            }
          }
        }
        System.out.println("Optimal train swapping takes "+swaps+" swaps.");
        swaps = 0;
      }
    }
  }
  </code></pre>
  
  <p>Example Input:</p>
  
  <pre class="lang-none prettyprint-override"><code>3
  3
  1 3 2
  4
  4 3 2 1
  2
  2 1
  </code></pre>
  
  <p>Example Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>Optimal train swapping takes 1 swaps.
  Optimal train swapping takes 6 swaps.
  Optimal train swapping takes 1 swaps.
  </code></pre>
  
  <p>My code prints until the second solution, then for some reason stops. I've tried to debug it and check what's going on step by step but it has driven me to a migraine point. Any insight is highly appreciated.</p>
  
  <p>...
  To be more precise it stops at the second <strong>for</strong> loop the third time around without taking anything into the array...and I don't know why! </p>
  
  <p>Another thing I found out is that to solve this problem the number of swaps for the case of the middle is 6, therefore the bubble sort wont be useful here, since it makes over 10 swaps thus yielding a wrong output, this is a separate issue to the original one I presented however. I still haven't figure out why it stops the third time around the loop where I assign values to the array for the third time.
  The input consists of:
  first line is number of cases. 
  this line enters the length of a train ex: 4
  this line enters the number of the wagons ex: 2 4 3 1
  the next following lines correspond to the following test cases whose structure is the same as the example.
  They ask you to arrange the train and tell the number of swaps made to make the train in order.</p>