1
public class sort {

    public static void main(String[] args)  { 
        int i =1;
        Scanner input = new Scanner(System.in);
        System.out.print("Please enter the number of data points: ");
        int data = input.nextInt();
        double [] userArray = new double[data];
        if(data < 0){
            System.out.println("The number should be posotive. Exiting.");
        } else {System.out.println("Enter the data:"); }
            while (i <= data) {
             int userInput = input.nextInt();
             i++;
        }         
        insertionSort(userArray);
    }

    static void insertionSort(double[] arr) {
        int i, j;
        double newValue;
        for (i = 1; i < arr.length; i++) {
            newValue = arr[i];
            j = i;
            while (j > 0 && arr[j - 1] > newValue) {
                arr[j] = arr[j - 1];
                j--;
            }
            arr[j] = newValue;
        }
        System.out.println("The sorted data is: " + arr);
    }
}

Currently the output looks like this:

Please enter the number of data points: 5 Enter the data:

4
2
5
3
1

The sorted data is: [D@3d4eac69

the numbers are all inputed by the user, and the end of the output "[D@3d4eac69" is always outputted when I print arr.

154 guy
  • 43
  • 7

0 Answers0