Question: Hello this is my method for a String Array insertion sort. It is returning bogus results to the console. Mainly just one array element over and over. Any help what needs to be changed is greatly appreciated.Thank you.

```
 public static void insertionSort(String[] a, int count) {
      int i, j;
      String Value;
      for (i = 1; i < count; i++) {
            Value = a[i];
            j = i - 1 ;
            while (j >= 0 && a[j].compareTo(Value)> 0) {
                  a[j+1] = a[j];
                  j=j-1;
            }
            a[i+1] = Value;

      }
       }

```

Answer: 
The code below works.

```
 public static void insertionSort(String[] a, int count) {
          int i, j;
          String Value;
          for (i = 1; i < count; i++) {
                Value = a[i];
                j = i;
                while (j > 0 && a[j-1].compareTo(Value)> 1) {
                      a[j] = a[j-1];
                      j--;
                }
                a[j] = Value;

```
check the code works fine

```
 public static void insertionSort(int array[]) {
        int n = array.length;
        for (int j = 1; j < n; j++) {
            int key = array[j];
            int i = j-1;
            while ( (i > -1) && ( array [i] > key ) ) {
                array [i+1] = array [i];
                i--;
            }
            array[i+1] = key;
            printNumbers(array);
        }

```

and to print the number i use function printNumbers(array)

```
 private static void printNumbers(int[] input) {

        for (int i = 0; i < input.length; i++) {
            System.out.print(input[i] + ", ");
        }
        System.out.println("\n");
    }

```