Given n, which is the number of strings taken as input. For each input use have to print “YES” or “NO” whether the current string is already present or not.
Input:
5
Geeks
Hello
Great
Geeks
Hello
Output:
No
No
No
Yes
Yes
Given n, which is the number of strings taken as input. For each input use have to print “YES” or “NO” whether the current string is already present or not.
Input:
5
Geeks
Hello
Great
Geeks
Hello
Output:
No
No
No
Yes
Yes
Maintain a set of strings and for every input string, check if the count of that particular string in the set is 0 or not. If it is 0, it means the string is unique, else it has been inputted before.
simpleAsThis
public class StringArray {
public static void main(String agrs[])
{
int c=0,j=0;
String a[] = {“Geeks”,“Hello”,“Great”,“Geeks”,“Hello”};
for(int i=0;i<5;i++)
{
for(j=0;j<i;j++)
{
c=0;
if(a[i]==a[j])
{
c++;
break;
}
}
if(c==0)
System.out.println("no");
else
System.out.println("yes");
}
}
}