class RemoveRep1 {
public static void main(String[] args) {
int[] arr = {6,2,9,6,1,2,6,7,8};
IsRep(arr);
ArrErg(arr);
}
public static void IsRep(int[] arr) {
int count = 0;
for (int i = arr.length-1;i >=0 ;i -- ) {
for (int j = 0;j < i ;j++ ) {
if (arr[j] == arr[i]) {
arr[j] = 0;
}
}
}
}
public static void ArrErg(int[] arr) {
for (int i = 0;i < arr.length ;i ++ ) {
if (arr[i] == 0)
continue;
System.out.print(arr[i] + " ");
}
}
}
class RemoveRep2 {
public static void main(String[] args) {
int[] arr = {6,2,9,6,1,2,6,7,8};
int count = 0;
count = IsRep(arr);
ArrErg(arr,count);
}
public static int IsRep(int[] arr) { //
int count = 0;
for (int i = arr.length - 1 - count;i >= 0 ;i -- ) {
for (int j = 0;j < i ;j ++ ) {
if (arr[i] == arr[j]) {
count ++;
for (int k = i;k < arr.length - count ;k ++ ) {
arr[k] = arr[k + 1];
}
}
}
}
return count;
}
public static void ArrErg(int[] arr,int count) {
for (int i = 0;i < arr.length - count ;i ++ ) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
}
|
|