package shuzu_practice;
public class Practice1 {
/*
需求1:
数组去重:
原数组:{1,9,8,6,3,5,1,9,8,7,2,6,6}
去重后数组:{1,9,8,6,3,5,7,2}
不允许使用集合
*/
public static void main(String[] args) {
int[] oldArr = {1, 9, 8, 6, 3, 5, 1, 9, 8, 7, 2, 6, 6};
int[] newArr = new int[oldArr.length];
newArr[0] = oldArr[0];
int index = 1;//定义新数组的长度
for (int i = 1; i < oldArr.length; i++) {
boolean l = false;
for (int j = 0; j < index; j++) {
if (oldArr[i] == newArr[j]) {
l = true;
}
}
if(!l){
newArr[index] = oldArr[i];
index++;
}
}
for (int i = 0; i < index; i++) {
System.out.println(newArr[i]);
}
}
}