这是我当前的代码:
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 )
{
}
}
当我手动输入数组时,我认为我遇到的问题出在某个地方。但我在那里变得朦胧?有没有人看到问题?我将此代码基于采用随机数组并对其进行排序的方法。谢谢。