The program stores the length of the bars in the array numbers. It traverses the array, comparing each element to the next one. If the next one is bigger than the current one, these two elements are swapped. The traversal of the array is repeated until no swap is necessary anymore.

while (!numbersSorted) {
  numbersSorted = true;
  for (int i = 0; i < numbers.length-1; i++) {
    if (numbers[i] > numbers[i+1]) {
      swap (numbers, i, i+1);
      numbersSorted = false;
      showNumbers (numbers);
    }
  }
}