即時通訊新的數組...我很難理解數組如何在這個代碼中工作... 我正在做一個冒泡排序。唯一我不明白的是變量d可以放在一個變量數組中嗎?爲什麼array [d] 5的值?
import java.util.Scanner;
public class bubbleSort
{
public static void main(String []args)
{
int n, c, d, swap;
Scanner in = new Scanner(System.in);
System.out.print("Input number of integers to sort");
n = in.nextInt();
int array[] = new int[n];
System.out.println("Enter " + n + " integers");
for (c = 0; c < n; c++)
array[c] = in.nextInt();
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d < n - c - 1; d++)
{
if (array[d] > array[d+1])
{
System.out.println("array d:" + array[d]); // value is 5
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
System.out.println("Sorted list of numbers");
for (c = 0; c < n; c++)
System.out.println(array[c]);
}
}