关于Java的Math.random()怎么使用?
有一道题,希望大家帮我做一下~谢谢了!Theprogramshouldsimulatethefollowingconversation:User:KnockKnock!W...
有一道题,希望大家帮我做一下~谢谢了!
The program should simulate the following conversation:
User: Knock Knock! Who’s There?
Computer: Dewey
User: Dewey who?
Computer: Dewey has to listen to all this knocking?
When the user asks the first question, the first response will be generated randomly by the compute. The second response for the second question will be based on the first response. The responses will be based on the table below:
Response to Who’s There? Next Response
Dewey Dewey has to listen all this knocking?
General Lee Generally I do not tell jokes, okay?
Ken Ken we not have some better jokes?
Wanda Wanda where I put my keys!
这道题就是我问问题,然后电脑随机回复。 展开
The program should simulate the following conversation:
User: Knock Knock! Who’s There?
Computer: Dewey
User: Dewey who?
Computer: Dewey has to listen to all this knocking?
When the user asks the first question, the first response will be generated randomly by the compute. The second response for the second question will be based on the first response. The responses will be based on the table below:
Response to Who’s There? Next Response
Dewey Dewey has to listen all this knocking?
General Lee Generally I do not tell jokes, okay?
Ken Ken we not have some better jokes?
Wanda Wanda where I put my keys!
这道题就是我问问题,然后电脑随机回复。 展开
2个回答
展开全部
幸亏有点英语水平
意思就是如果第一个问题的回答是General Lee 第二个就必须是Generally I do not tell jokes, okay?其他一样 但是第一个问题的回答是随机的
public class Computer {
private static final String[] names = {"Dewey", "General Lee", "Ken", "Wanda"};
private static final String[] answers = {
"Dewey has to listen all this knocking?",
"Generally I do not tell jokes, okay?",
"Ken we not have some better jokes?",
"Wanda where I put my keys!"};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
System.out.print("User:");
String str = in.next();
if (str.equals("quit")) {
System.out.println("Bye!");
System.exit(0);
}
System.out.print("Computer:");
int number = (int) (Math.random() * 4);
System.out.println(names[number]);
System.out.print("User:");
str = in.next();
if (str.equals("quit")) {
System.out.println("Bye!");
System.exit(0);
}
System.out.print("Computer:");
System.out.println(answers[number]);
}
}
}
意思就是如果第一个问题的回答是General Lee 第二个就必须是Generally I do not tell jokes, okay?其他一样 但是第一个问题的回答是随机的
public class Computer {
private static final String[] names = {"Dewey", "General Lee", "Ken", "Wanda"};
private static final String[] answers = {
"Dewey has to listen all this knocking?",
"Generally I do not tell jokes, okay?",
"Ken we not have some better jokes?",
"Wanda where I put my keys!"};
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
System.out.print("User:");
String str = in.next();
if (str.equals("quit")) {
System.out.println("Bye!");
System.exit(0);
}
System.out.print("Computer:");
int number = (int) (Math.random() * 4);
System.out.println(names[number]);
System.out.print("User:");
str = in.next();
if (str.equals("quit")) {
System.out.println("Bye!");
System.exit(0);
}
System.out.print("Computer:");
System.out.println(answers[number]);
}
}
}
TableDI
2024-07-18 广告
2024-07-18 广告
VLOOKUP是Excel中用于垂直查找的函数,其基本用法包括四个参数:1. 查找值:即在数据表首列中需要搜索的值。2. 数据表:包含查找值的单元格区域或数组。3. 返回值所在列数:指定返回查询区域中第几列的值。4. 查找方式:选择精确匹配...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |