我想在Java中创建一个聊天机器人,但我不知道如何开始? 我试过下面的代码,但没有得到我确切需要的东西。 在这个程序中,我不得不写出所有问题的可能性。 如果有任何人有解决方案,请帮助我。如何在java中制作虚拟聊天机器人?
import java.io.*;
public class Chatbot
{
public static void main(String[]args) throws IOException
{
String hel = new String("Hello");
String hel1 = new String("HELLO");
String hel2 = new String("hello");
String hel3 = new String("Hii");
String hel4 = new String("Hiii");
String hel5 = new String("hii");
String hel6 = new String("hiii");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is Your Name?");
String name = br.readLine();
System.out.println("Hello "+name+"..");
String hellorep = br.readLine();
if(hellorep .equals(hel))
{
System.out.println("Hello there...");
}
else if(hellorep .equals(hel1))
{
System.out.println("Hello there...");
}
else if(hellorep .equals(hel2))
{
System.out.println("Hello there...");
}
else if(hellorep .equals(hel3))
{
System.out.println("Hii");
}
else if(hellorep .equals(hel4))
{
System.out.println("Hiii");
}
else if(hellorep .equals(hel5))
{
System.out.println("Hii");
}
else if(hellorep .equals(hel6))
{
System.out.println("Hiii");
}
else
{
System.out.println("Please type Again I Didn't get you..");
}
}
}
和多数民众赞成这样做的一个简单的方法,而不使代码看起来像废话 – Hydrox