これが私の現在のコードです:
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 )
{
}
}
私が抱えていると思う問題は、配列を手動で入力するときのどこかにあると思います。しかし、私はそこでぼやけますか?誰かが問題を見ますか?このコードは、ランダムな配列を取得してソートするメソッドに基づいています。ありがとう。