Can anyone tell me what im doing wrong here ? I just want to detect the last word of the sentence and if not found to show "Not found." here is the code:
String[] items = { "Iphone", "Computer", "Car" };
String field = Field.getText();
String text = "I want a ";
Scanner scan = new Scanner(text);
for (int i = 0; i < text.length(); i++) {
while (scan.hasNext()) {
String next = scan.next();
for (int j = 0; j < items.length; j++) {
if (next.equals(items[j])) {
infoLabel.setText("You want a: "+items[j]);
} else {
infoLabel.setText("Item not found.");
}
}
}
}