JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.HashMap;
import java.util.Scanner;
public class SimpleChatBot {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HashMap<String, String> responses = new HashMap<>();
responses.put("hello", "Hi there! How can I help you?");
responses.put("how are you", "I'm doing great!");
responses.put("bye", "Goodbye! Have a nice day.");
responses.put("what is your name", "I'm your personal assistant but im getting trained!!");
System.out.println("Chatbot: Hello! Type 'exit' to end the chat.");
while (true) {
System.out.print("You: ");
String userInput = scanner.nextLine().toLowerCase();
if (userInput.equals("exit")) {
System.out.println("Chatbot: Goodbye!");
break;
}
boolean found = false;
for (String key : responses.keySet()) {
if (userInput.contains(key)) {
System.out.println("Chatbot: " + responses.get(key));
Enter to Rename, Shift+Enter to Preview
OUTPUT
Запуск