我想取回整数类型的洗牌数组,所以我写了这段代码,但它不起作用......在这段代码中,我希望每次 Scase 类的每个对象都有新值......但这必须来自 5,50,100.. .
class Scase {
int label;
int value;
public static int arr[] = {5,50,100};
public static int[] toarr(List<Integer> list)
{
int[] ret = new int[list.size()];
for (int i = 0; i < ret.length; i++)
ret[i] = list.get(i);
return ret;
}
public static void main(String args[])
{
Scase obj[] = new Scase[1];
List<Integer> lst = new ArrayList<Integer>();
lst = Arrays.asList(arr);
Collections.shuffle(lst);
int ar[];
ar = toarr(lst);
for(int i = 0; i <= 2; i++) {
obj[i].value = ar[i];
}
System.out.println(obj[0].label + " " + obj[0].value);
System.out.println(obj[1].label + " " + obj[1].value);
System.out.println(obj[2].label + " " + obj[2].value);
}
}