Q.7 print the non-repeated elements from a Random Array i/p;{10,20,4,5,6,10,5} o/p:{20,4,6}public class NonRepeat {
public static void main(String[] args) {
int arr[]={10,20,4,5,6,10,5};
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
if(arr[i]==arr[j]){
arr[i]=arr[j]=-1;
}
}
}
for(int a:arr){
if(a!=-1)
System.out.print(a+" ");
}
}
}
No comments:
Post a Comment