JAVA编程:两int数组A,B。A长度为100并且有值无重复,B长度为99无值。 把A数组中的数随机添加到B数组中去,求出没有在B数组中那个数。
------解决方案--------------------
------解决方案--------------------
- Java code
int[] a = new int[100];//假设已经赋值 List<Integer> list = new ArrayList<Integer>(); for(int i=0;i<100;i++){ list.add(a[i]); } int b[] = new int [99]; int index = new Random().nextInt(); for(int i=0;i<99;i++){ int j = index%list.size();//根据index随即取值 b[i] = list.get(j); list.remove(j);//剔除已经选过的元素 }