I was trying to read the following input from the user I need to save the input as a string of words but with no duplications and it stops taking input when it hits "zz".
but my code does not read watermelon and strawberry and I do not know why or how to fix it. Every time if there is a bunch of leading spaces my code ignores the word and goes for the one next to it.
This is my code
String text="";
while (keyboard.hasNext()) {
String word = keyboard.next().trim().toLowerCase();
if (!word.equals("zz")) {
if(!text.contains(word)) {
if (text.length()==0) {
text=word;
}
else {
text+=" "+word;
}
}
}
else {
keyboard.close();
break;
}
}