本帖最后由 Fightin黑马 于 2014-9-19 18:11 编辑
数组去重复,例如: 原始数组是{1,2,3,4,3,2,1,5,6,7,9},得到结果{1,2,3,4,5,6,7,9}
class Test
{
public static void main(String[] args)
{
int[]arr1={1,2,3,4,3,2,1,5,6,7,9};
int[]arr2=new int[arr1.length];
int count=1;
arr2[0]=arr1[0];
loop2:
for(int i=0;i<arr1.length;i++){
for(int j=0;j<count;j++){
if(arr2[j]!=arr1){
if(j==count-1){
arr2[count]=arr1;
count++;
}
continue ;
}else{
continue loop2;
}
}
}
int arr3[]=new int[count];
for(int i=0;i<count;i++){
arr3=arr2;
}
print(arr1);
System.out.println();
print(arr3);
}
public static void print(int arr[]){
for(int i=0;i<arr.length;i++){
System.out.print(arr+"\t");
}
}
} |
|