简单的java小程序 50
简单的java小程序做出一个聊天的程序,程序检测到单词就做出相应回答第一句是Thedoctorisin.what'sonyourmind?然后根据下面这张表做题如果用户没...
简单的java小程序做出一个聊天的程序,程序检测到单词就做出相应回答
第一句是The doctor is in.
what 's on your mind?
然后根据下面这张表做题
如果用户没写关于上面的单词,就随机用下面这几句话
What does that suggest to you?
I see.
Can you elaborate. 展开
第一句是The doctor is in.
what 's on your mind?
然后根据下面这张表做题
如果用户没写关于上面的单词,就随机用下面这几句话
What does that suggest to you?
I see.
Can you elaborate. 展开
1个回答
展开全部
import java.util.Scanner;
import java.util.TreeMap;
public class Discourse {
static TreeMap<String, String> keywords = new TreeMap<>();
static String[] randomAnswers = {
"What does that suggest to you?",
"I see.",
"Can you elaborate?"};
public static void main(String[] args) {
keywords.put("always", "Can you think of a specific example?");
keywords.put("because", "Is that the real reason?");
keywords.put("sorry", "Please don't apologize.");
keywords.put("maybe", "You don't seem very certain.");
keywords.put("i think", "Do you really think so?");
keywords.put("you", "We were discussing you,not me.");
keywords.put("yes", "Why do you think so?");
keywords.put("no", "Why not?");
System.out.println("The doctor is in. \nWhat 's on your mind?");
Scanner scanner = new Scanner(System.in);
String input = null;
String answer = null;
while (scanner.hasNextLine()) {
input = scanner.nextLine();
if(input.equals("bye")){
System.out.println("Bye!");
return;
}
if(isContained(input)){
answer = keywords.get(input);
} else {
answer =randomAnswers[ (int) (Math.random() * 3)];
}
System.out.println(answer);
}
scanner.close();
}
private static boolean isContained(String input) {
return keywords.containsKey(input);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询