I need to check the array to see if the user input is already present, and display a message as to whether it is or isn\'t there. The first part is working, but I tried to creat
You're going to have to loop through the entire array and check if scan.next() equals any of them - if so return true - as such:
String toCheck = scan.next();
for (String string : i) { //For each String (string) in i
if (toCheck.equals(i)) {
System.out.println("The word has been found");
return;
}
}
System.out.println("The word has not been found");
This supposes you call WordCheck()
, passing the array to it - this method also has to be static for you to call it from the main()
method.