I'm trying to create a chatbot using a loop that will have a conversation with the user, and will stop when the user types "bye". Kind of like what i'm trying to do here, except i suck at programming:
Scanner sc = new Scanner (System.in);
String question;
System.out.println("Hello");
do
{
question = sc.nextLine();
if (question.equals("how are you");
{
System.out.println("good");
}
if (question.equals("bye"))
{
System.out.println("bye");
break;
}
} while (!sc.nextLine().equals("bye"));
}
}
You should take your "Bye" out of the loop. So if
sc.nextLine().equals("bye")
it finishes the loop, say "bye" and finishes the program.