I haven't used any programming in 20 years and back then it was Basic.
I am trying to write an (extremely) simple chat bot program just to get used to if/then with the scanner.
One thing I can't figure out how to do is read the user input and check for two words. In my example (line 20) I am trying to find the word "hello" and the word "there". If the input contains both words it will return "success". I've gotten this to work to some degree if "hello" and "there" are adjacent to each other but I want a positive return if they exist anywhere in the user's input, for example: "hello, what are you doing there?" or "hello there"
Additionally, something I haven't learned yet is how to make the code loop back up to the top after the user submits data rather than the program terminating.
Be simple with me. I am to learn basics. Thank you so much!
package chatBot; import java.util.Scanner; public class chatBotClass { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner (System.in); System.out.println("Program begins"); String uInput = scan.nextLine(); //next will find the next word the user enters if (uInput.contains("hello") + uInput.contains("there")) { System.out.println("success"); } else if (uInput.equals("hi")) { System.out.println(uInput +"!"); } else if (uInput.equals("Hello")) { System.out.println(uInput); } else { System.out.println("NO WORD ERROR");} } private static String contains(String string) { return null; } }