java中, 如何将数组1,2,3,4,5 随机排列,并赋予变量a,b,c,d,e 新手不懂

2025-06-26 20:53:10
推荐回答(2个)
回答1:

Integer a, b,c,d,e ;
Integer[] arr = new Integer[]{1,2,3,4,5};
List list = Arrays.asList(arr);
Collections.shuffle(list);//打乱
arr = list.toArray(arr);
int idx = 0 ;
a = arr[idx++];
b = arr[idx++];
c = arr[idx++];
d = arr[idx++];
e = arr[idx++];

回答2:

qqqqqqmark