int[] arr = {6,2,9,6,1,0,2,6,0,7,8 };
int length;
int c = 0;
int d = 0;
for (; c < arr.length; c++) {
if (arr[c] == 0) {
System.out.println("0出现的索引是" + c);
d++;
break;
}
}
int x = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < i; j++) { // 将arr中第二次出现并且重复的元素变为0
// 629001007800000
if (arr[j] == arr[i]) {
arr[i] = 0;
}
}
}
int[] arr2 = new int[arr.length]; //{ 1,2,0, 0, 0,3,45,0,6,5,40,0,0,0 };
int count=0;
for(int i =0;i<arr.length;i++){
if(i == c){
arr2[count]=arr[i];
count++;
}else if(arr[i]!=0){
arr2[count] = arr[i];
count++;
}
}
for(int i =0;i<count;i++){
System.out.print(arr2[i]+" ");
} |