0
我想找回整數類型的混洗數組,因此我編寫了這段代碼,但它不工作......在此代碼中,我希望每次分類Scase的每個對象都有新的值...但從5,50,100必須...將列表轉換爲int數組
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);
}
}
請添加一個標籤,指明您正在使用的語言(C#?Java?...?)。此外,這是關於列表數組轉換還是關於洗牌?您可能想要修改你的問題標題。 –