+ 4
Can you explain this code frnds
2 Respostas
+ 3
array[]={"black","white","black","black","black"};
String temp=null; // string which have empty value ""
int count=0;
//array.length the size of array
for(int i=0;i<array.length;i++){
temp=array[i]; //assign the value each array element to temp
for(int j=0;j<array.length;j++){
if(temp==array[j]) //to check the the temp value is equal to each value of the array elements
{count+=1;} //if the values are equal count increase by one
}if(count<=1){System.out.println("non repeating element is "+temp);}count=0;}
}
finally it prints
non repeating element is white
+ 3
It prints out all elements of a string array that have no duplicates within the array.