我对Java很新,我正在尝试创建一个聊天机器人。我有一个主要方法,然后有一个响应的方法。尽管当我尝试在主要方法中调用响应方法时,它突出显示了单词Response并说:方法ChatCode中的Response不能应用于给定的类型; 必需:java.lang.String;发现:没有参数;原因:实际的和正式的参数列表长度为什么我不能在我的程序中调用这个方法?
public class ChatCode{
public static String main(String input){
Scanner sc = new Scanner(System.in);
System.out.println("Hello!");
input = sc.nextLine();
while(input != ("Bye")){
Response();
}
System.out.println("Bye!");
}
不同那么这就是我的回答方法
public static String Response(String output){
Scanner sc = new Scanner(System.in);
input = input.toLowerCase();
input = input.trim();
String output;
if(input.indexOf("hi!") >= 0
|| ("hi") >= 0
|| ("hello!") >= 0
|| ("hello") >= 0){
output = "Hello!";
}
else if(input.indexOf("whats up?") >= 0
|| ("what's up?") >= 0
|| ("whats up") >= 0
|| ("what's up") >= 0){
output = "Nothing much, how about you?";
}
else if(input.indexOf("how are you?") >= 0
|| ("how are you") >= 0){
output = "I am great, how about you?";
}
return output;
}
任何反馈,将不胜感激!!!!
(0)'input!=(“Bye”)' - > [如何比较Java中的字符串?](http:// stackoverflow。COM /问题/ 513832 /怎么办 - 我 - 比较 - 字符串,在Java的); (1)'Response(String output){'期望参数,所以你不能通过'Response()'调用它; (2)方法名称应以小写开头。 – Pshemo
您的方法'public static String Response(String output){'被声明为需要'String'参数,但是您使用'Response();',这不是同一件事情,您必须将它传递给'null '或者'String'值 – MadProgrammer
需要在这里传递一个字符串,while(input!=(“Bye”)){Response; //像这样 - > Response(input); } –