title: My bubble sorting algorithm in Java never stops sorting and doesnt return anything
body: <p>I'm trying to make a bubble sorting algorithm in Java however my code just keeps going when It's supposed to sort without returning anything. When the program is run it gets as far as printing the array before the sorting however after that nothing happens but the program doesnt stop it keeps running</p>
  
  <pre><code>package src;
  import java.util.Scanner;
  import java.util.Random;
  import java.util.ArrayList;
  import java.util.List;
  
  public class bubbleSort {
  
      public static void main(String[] args) {
  
          int length = getLength();
  
          List&lt;Integer&gt; randomList = createList(length);
  
          System.out.println("The list before sorting:\n" + randomList);
  
          List&lt;Integer&gt; newList = sortList(randomList, length);
  
          System.out.println("The list after sorting:\n" + newList);
  
  
  
      }
  
      public static int getLength() {
          System.out.println("Please enter how long you want the array to be");
  
          Scanner reader = new Scanner(System.in);
  
          int length = Integer.parseInt(reader.nextLine());
  
          return length;
      }
  
      public static List&lt;Integer&gt; createList(int length) {
          Random rand = new Random();
  
          List&lt;Integer&gt; randomList = new ArrayList&lt;Integer&gt;();
  
          for(int x = 0 ; x &lt; length ; x++){
              int randomnumber = rand.nextInt((100 - 1) + 1) + 1;
              randomList.add(randomnumber);
          }
  
          return randomList;  
      }
  
      public static List&lt;Integer&gt; sortList(List&lt;Integer&gt; randomList, int length){
          boolean sorted = false;
  
          while(sorted == false){
              sorted = true;
  
              for(int x = 0 ; x &lt; (length - 1) ; x++) {
                  if(randomList.get(x) &gt; randomList.get(x + 1)) {
                      sorted = false;
                      int temp = randomList.get(x + 1);
                      randomList.set((x + 1), (x));
                      randomList.set((x + 1), temp);
                  }
              }
          }
  
          return randomList;
      }
  
  }
  </code></pre>