Java 如何获取手动输入的数组并对其进行排序?

Java 如何获取手动输入的数组并对其进行排序?,java,arrays,sorting,input,Java,Arrays,Sorting,Input,以下是我当前的代码: public static void main (String [] args) { try { System.out.println("Please enter the amount of numbers in the array"); int arraySize2 = keyboard.nextInt (); System.out.println("Please enter the numbers in th

以下是我当前的代码:

public static void main (String [] args)
{
 try
      {
        System.out.println("Please enter the amount of numbers in the array");
        int arraySize2 = keyboard.nextInt ();
        System.out.println("Please enter the numbers in the array seperately.");
        int[] array = new int[arraySize2];
        for(int b=0; b<=arraySize2-1; b++){
          array[b] = keyboard.nextInt(20);}    
        for (int i = 0; i < array.length -1; i++){
          int minPos = i;
          for (int j = i; j < array.length; j++){
            if (array[j] < array[minPos])
              minPos = j; }       
          // swaps minimum value with current location
          int temp = array[i];
          array[i] = array[minPos];
          array[minPos] = temp; }
      }
      catch( ArrayIndexOutOfBoundsException e ) 
      {

      }
}
我认为我遇到的问题是,当我手动输入数组时。但我在那里变得模糊了?有人看到问题吗?我基于一个方法编写了这段代码,该方法使用一个随机数组并对其进行排序。谢谢。

为什么不直接使用树形图并不断输入值呢。最后,对每个循环使用迭代器来打印或稍后使用这些数字


或者,您可以使用二叉搜索树并不断向其中插入数据。最后进行顺序遍历。

keyboard.nextin20;读入以20为基数的数字-您确定要这样做吗?除此之外,代码没有任何问题,除了格式问题。。;您可以使用Arrays.sort而不是手动选择排序。@Anthales,但这可能是家庭作业,因此不允许使用Arrays.sort: