LotteryDrawing.java的问题.苦思冥想想不出来numbers【r】 = numbers【n-1】;n--是怎么解释,

问题描述:

LotteryDrawing.java的问题.苦思冥想想不出来numbers【r】 = numbers【n-1】;n--是怎么解释,
Scanner in = new Scanner(System.in);
System.out.print("How many numbers do you need to draw:");
int k = in.nextInt();
System.out.priint("How mang highest numbers do you need to draw: ");
int n = in .nextInt();
int[] numbers = new int[n];
for(int i = 0 ; i {
int[i] = i +1;//用1,2,3.n来填满数组;
}
int[] result = new int[k];
for(int i = 0 ; i {
int r = (int)(Math.random()*n);
result[i] = numbers[r];//用随机生成的数值作为下标r,进行r+1运算后赋给result[i];
numbers[r] = numbers[n-1];//为了防止出现相同的随机值!这里我就看不懂了.什么意思啊
n--;//为了防止出现相同的随机值!这里我就看不懂了.什么意思啊
}

numbers[r] = numbers[n-1];//第一次:i=0如果r==n-1,基本没意义.如果r=0),此时的numbers[r]的值就和result[i...