Java 选择排序出错

Java 选择排序出错,java,arrays,sorting,selection,Java,Arrays,Sorting,Selection,我正在尝试使用数组上的可比较项进行选择排序。我不知道为什么它不起作用。如果有人能看一看,并帮助我找到什么是不工作,这将是伟大的!谢谢大家! public static Comparable[] no = new Comparable[100]; public static Comparable[] gen1() { Random random = new Random(); for(int i=0;i<no.length;i++) { no[i]

我正在尝试使用数组上的可比较项进行选择排序。我不知道为什么它不起作用。如果有人能看一看,并帮助我找到什么是不工作,这将是伟大的!谢谢大家!

public static Comparable[] no = new Comparable[100];

public static Comparable[] gen1()
{
    Random random = new Random();
    for(int i=0;i<no.length;i++)
    {
        no[i] =random.nextInt();
    }
    return no;
}   

public static Comparable[] selectionSort (Comparable no[])
   {
      int min;
      Comparable temp;

      for (int index = 0; index < no.length-1; index++)
      {
         min = index;
         for (int scan = index+1; scan < no.length; scan++)
            if (no[scan].compareTo(no[min]) < 0)
               min = scan;
         temp = no[min];
         no[min] = no[index];
         no[index] = temp;
      }
      return no;
   }

public static void main(String[] args)
{
    System.out.println("Original Array:");
    System.out.println(Arrays.toString(gen1()));
    System.out.println("Sorted Array:");
    System.out.println(selectionSort(no));

}
公共静态可比[]否=新可比[100];
公共静态可比[]第1代()
{
随机=新随机();

对于(inti=0;i您没有指定您的问题是什么,但在main的最后一行中您应该这样做

  System.out.println(Arrays.toString(selectionSort(no)));

输出在我看来是排序的。

我刚刚试过你的代码,排序对我来说似乎很好。我不得不将打印排序数组的行更改为
System.out.println(Arrays.toString(selectionSort(no)))
这对你不起作用吗?如果不起作用,你能具体说明什么不起作用吗?啊!谢谢!这总是最明显的事情!