/** * 随机获取一个肯定的回答 * @return 肯定的回答 */ private static String getRandomPositiveAnswer() { int randomIndex = new Random().nextInt(positiveAnswers.length); return positiveAnswers[randomIndex]; } /** * 随机获取一个否定的回答 * @return 否定的回答 */ private static String getRandomNegativeAnswer() { int randomIndex = new Random().nextInt(negativeAnswers.length); return negativeAnswers[randomIndex]; } }帮我添加注释
时间: 2024-04-27 10:21:09 浏览: 13
// 随机获取一个肯定的回答
// @return 肯定的回答
private static String getRandomPositiveAnswer() {
// 生成一个随机数,范围为肯定的回答数组的长度
int randomIndex = new Random().nextInt(positiveAnswers.length);
// 返回对应随机数的肯定的回答
return positiveAnswers[randomIndex];
}
// 随机获取一个否定的回答
// @return 否定的回答
private static String getRandomNegativeAnswer() {
// 生成一个随机数,范围为否定的回答数组的长度
int randomIndex = new Random().nextInt(negativeAnswers.length);
// 返回对应随机数的否定的回答
return negativeAnswers[randomIndex];
}
// ChitChatBot类,用于实现与用户的对话功能
public class ChitChatBot {
// 肯定的回答数组
private static String[] positiveAnswers = { "是的", "当然", "没错", "绝对是这样的", "可以肯定", "没问题" };
// 否定的回答数组
private static String[] negativeAnswers = { "不是的", "当然不是", "绝对不是", "不可能", "不行", "不对" };
// 随机获取一个肯定的回答
// @return 肯定的回答
private static String getRandomPositiveAnswer() {
// 生成一个随机数,范围为肯定的回答数组的长度
int randomIndex = new Random().nextInt(positiveAnswers.length);
// 返回对应随机数的肯定的回答
return positiveAnswers[randomIndex];
}
// 随机获取一个否定的回答
// @return 否定的回答
private static String getRandomNegativeAnswer() {
// 生成一个随机数,范围为否定的回答数组的长度
int randomIndex = new Random().nextInt(negativeAnswers.length);
// 返回对应随机数的否定的回答
return negativeAnswers[randomIndex];
}
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)