Sorting in java


#1

can anyone help me in sorting an array

Scanner input = new Scanner(System.in);

            System.out.println("How many numbers do you want to enter?");
            int num = input.nextInt();
            int array[] = new int[num];
            System.out.println("Enter the " + num + " numbers now.");
            for (int i = 0 ; i < array.length; i++ ) 
                {
                    array[i] = input.nextInt();
                }

i used this code to input an array.. now i want this array to be sorted and i also want to count the occurrence of each number in the array
`


#2

What are you missing in order to do so? (Seems straight-forward, can't guess where the problem is)


#3

I'm not quite sure what you have to do here, maybe you have to change it to the following:

            Scanner input = new Scanner(System.in);
            System.out.println("How many numbers do you want to enter?");
            int num = input.nextInt();
            int array[] = new int[num];
            System.out.println("Enter the " + num + " numbers now.");
            for (int i = 0; i < array.length; i++) {
             array[i] = input.nextInt();
            }

It's a bit more sorted.


#4

thanks for this yeah.. really helpfull.. i m currently learning java thats why i m not so good with the syntax and stuff. tho i've a background of working with c++...


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.