JAVA传参传的是地址,实际n,n2,no,sequence指向的都是同一个数组所以一样的,int [] n2= getSequence(n);这一名实际是多余的,
public static int[] getSequence(int[] no) 方法也可以是无返回值的:
import java.util.Random;
public class Lx {
public static void main(String[] args) {
int[] n ={0,1,2,3,4,5,6,7,8,9};
//int [] n2= getSequence(n);
getSequence(n);
for(int a:n){
System.out.print(a);
}
}
public static void getSequence(int[] no) {
int[] sequence = no;
Random random = new Random();
for(int i = 0; i < no.length; i++){
int p = random.nextInt(no.length);
int tmp = sequence[i];
sequence[i] = sequence[p];
sequence[p] = tmp;
}
random = null;
//return sequence;
}
} |