Insertion Sort - So akzeptieren Sie Eingaben und drucken das sortierte Array

Ich habe versucht, ein Programm zum Sortieren von Einfügungen zu erstellen, das einen beliebigen Datentyp (Int, Double, String) akzeptiert, und dann das sortierte Array gedruckt. Ich weiß, dass mein Code funktioniert, aber ich kann das eigentliche Problem nicht herausfinden.

import java.util.*;
public class MyInsertionSort 

{
    public static void main(String[] args) 
    { 
        Scanner in = new Scanner(System.in);
        System.out.print("Enter anything you want");
        String insertionSort = in.nextLine(); 
        int num=Integer.parseInt(insertionSort);
        String array[] = new String [num];
        for (int i = 0; i < array.length; i++)
        {
            System.out.print("Input the Number at array index "+i+": ");
            array[i] = in.nextLine();
        }

    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); 
        }
    }
} 

Antworten auf die Frage(2)

Ihre Antwort auf die Frage