import java.util.*;
class FindNumberOFDuplicate
{ //Write a program to find the unique element in arrays.
public static void main(String[] args)
{
int c=0;
int arr[]={10,20,20 ,30,40,50,10,20};
System.out.println("Original:"+Arrays.toString(arr));
System.out.print("Unique Element:");
for(int i=0;i<arr.length;i++){
int j;
for( j=0;j<i;j++){
if(arr[i]==arr[j]){
c++;
break;
}
}
if(i==j){
System.out.print(arr[i]+" ");
}
}
System.out.print("\nCount Duplicate:"+c);
System.out.println();
}
}
2. A second method to find the unique element in the array.
for(int i=0;i<arr.length;i++){
}
class FindNumberOFDuplicate
{ //Write a program to find the unique element in arrays.
public static void main(String[] args)
{
int c=0;
int arr[]={10,20,20 ,30,40,50,10,20};
System.out.println("Original:"+Arrays.toString(arr));
System.out.print("Unique Element:");
for(int i=0;i<arr.length;i++){
int j;
for( j=0;j<i;j++){
if(arr[i]==arr[j]){
c++;
break;
}
}
if(i==j){
System.out.print(arr[i]+" ");
}
}
System.out.print("\nCount Duplicate:"+c);
System.out.println();
}
}
Comments
Post a Comment