title: TestClass for simple sorting algorithms gives unlogical results
body: <p>I have the following Class with some sorting algorithms like MaxSort, BubbleSort, etc.:</p>
  <pre><code>class ArrayUtility {
  
     public static int returnPosMax(int[] A, int i, int j) {
         int max = i;
         int position = 0;
         for(int c = 0; c &lt;= j; c++){
             if(c &gt;= i){
                 if(A[c] &gt; max){
                  max = A[c];
                  position = c;
                  }
             }
         }
        return position;
     }
  
     public static int returnMax(int[] A, int i, int j) {
        return A[returnPosMax(A, i, j)];
     }
  
     public static void swap(int[] A, int i, int j) {
         int b = A[i];
         A[i] = A[j];
         A[j] = b;
     }
  
     public static void MaxSort(int[] A) {
         int posMax;
         for(int i = A.length - 1; i &gt;= 0; i--){
             posMax = returnPosMax(A, 0, i);
             swap(A, posMax, i);
         }
     }
  
     public static void BubbleSort(int[] A) {
         boolean flag = true;
         while (flag != false){
             flag = false;
             for(int i = 1; i &lt;= A.length - 1; i++){
                 if(A[i-1]&gt;A[i]){
                     swap(A, i-1, i);
                     flag = true;
                 }
             }
             if(flag = false) {
                 break;
             }
             for(int i = A.length - 1; i &gt;= 1; i--){
                 if(A[i-1]&gt;A[i]){
                     swap(A, i - 1, i);
                     flag = true;
                 }
             }
         }
     }
  
     public static void BubbleSortX(int[] A) {
         boolean flag = true;
         while (flag != false){
             flag = false;
             for(int i = 1; i &lt;= A.length - 1; i++){
                 if(A[i-1]&gt;A[i]){
                     swap(A, i-1, i);
                     flag = true;
                 }
             }
         }
     }
  
  }
  </code></pre>
  <p>Now i have to create a Test Class to evaluate the different sorting algorithms for different lengths of randomly created Arrays:</p>
  <pre><code>import java.util.Random;
  import java.util.Arrays;
  
  public class TestSorting{
      public static void main(String[] args){
          int[] lengthArray = {100, 1000, 10000, 100000};
          for(int i = 0; i &lt;= lengthArray.length - 1; i++){
              int[] arr = new int[i];
              for(int j = 0; j &lt; i; j++){
                  Random rd = new Random();
                  int randInt = rd.nextInt();
                  arr[j] = randInt;
              }
              /* long startTime = System.nanoTime();
              ArrayUtility.MaxSort(arr);
              long cpuTime = System.nanoTime() - startTime;
              System.out.println(&quot;Time: &quot; + cpuTime + &quot; - Array with Length: &quot; + lengthArray[i] + &quot; Using MaxSort&quot;); */
              
              /* long startTime = System.nanoTime();
              ArrayUtility.BubbleSortX(arr);
              long cpuTime = System.nanoTime() - startTime;
              System.out.println(&quot;Time: &quot; + cpuTime + &quot; - Array with Length: &quot; + lengthArray[i] + &quot; Using BubbleSortX&quot;); */
              
              long startTime = System.nanoTime();
              ArrayUtility.BubbleSort(arr);
              long cpuTime = System.nanoTime() - startTime;
              System.out.println(&quot;Time: &quot; + cpuTime + &quot; - Array with Length: &quot; + lengthArray[i] + &quot; Using BubbleSort&quot;);
              
              /*long startTime = System.nanoTime();
              Arrays.sort(arr)
              long cpuTime = System.nanoTime() - startTime;
              System.out.println(&quot;Time: &quot; + cpuTime + &quot; - Array with Length: &quot; + lengthArray[i] + &quot; Using BubbleSort&quot;); */
          }
      }
  }
              
  </code></pre>
  <p>Now when i run a certain sorting algorithm (i set the others as comment for the meantime), i get weird results, for example</p>
  <pre><code>Time: 1049500 - Array with Length: 100 Using BubbleSort
  Time: 2200 - Array with Length: 1000 Using BubbleSort
  Time: 13300 - Array with Length: 10000 Using BubbleSort
  Time: 3900 - Array with Length: 100000 Using BubbleSort
  </code></pre>
  <p>And any time i run the test i get different results, such that Arrays with 10 times the length take less time to sort, also i dont understand why the array with 100 integers takes so long.</p>