上段粗糙的代码:
public static int[] removeCu(int a) {
// 通过指定数字a删除它
// 比如这个数字为3
ArrayList lst = new ArrayList();
for (int i = 0; i < coun.length; i++) {
if (coun[i] != a) {
lst.add(coun[i]);
}
}
int[] rs = new int[lst != null ? lst.size() : 0];
for (int j = 0; j < rs.length; j++) {
rs[j] = Integer.parseInt(lst.get(j).toString());
}
System.out.println(Arrays.toString(rs));
return rs;
}
上段粗糙的代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static int[] removeCu(int a) {
// 通过指定数字a删除它
// 比如这个数字为3
ArrayList lst = new ArrayList();
for (int i = 0; i < coun.length; i++) {
if (coun[i] != a) {
lst.add(coun[i]);
}
}
int[] rs = new int[lst != null ? lst.size() : 0];
for (int j = 0; j < rs.length; j++) {
rs[j] = Integer.parseInt(lst.get(j).toString());
}
System.out.println(Arrays.toString(rs));
return rs;
}
import java.util.ArrayList;
import java.util.Iterator;
public class Java0703 {
public static void main(String[] args) {
int [] coun={1,1,1,2,2,3,3,3,4,4,5,5,7,7};
ArrayList al = new ArrayList();
for (int i=0;i
al.add(coun[i]);
}
Iterator it = al.iterator();
while(it.hasNext())
System.out.print(it.next()+" ");
}
}