0

Aim is to get an array and arrange it accending, and print

package habeeb; 
import java.util.*;
public class Habeeb {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] num = new int[10];
        int i, count=0, m;
        System.out.println("Enter the integers, with 0 to end the array" );
        for( i=0; i<num.length; i++){
            num[i]= input.nextInt();

Zero breaks the array here

            if(num[i]==0)
            break;
            count++;

Calling the function here\

        }
        Sorting(num, count);

The function sorting is here

    }
    public static void Sorting(int[] sort, int con){
        if(con<0)
            return;
        int j, max=0, coun=0, temp;
        for(j=0; j<con; j++){
            if(sort[j]>max)
                max=sort[j];
            coun=j;
        }

here am swaping the last value in the array for any index thats the highest

        temp=sort[con];
        sort[con]=sort[coun];
        sort[coun]=temp; 

Calling the function again here(recursive)

        Sorting(sort, con-1);

Here am printing, why is it not printing

        for(j=0; j<con; j++){
            System.out.println(sort[j]);
        }
    }
}
4

1 に答える 1

0

Arrays.sort()を使用しない理由はありますか?

あなたがしなければならないのは、電話するだけです

Arrays.sort(num);

これは配列を変更し、ソートされたコピーを作成しないので注意してください!

于 2013-04-11T07:50:04.880 に答える