首页上一页 1 下一页尾页 1 条记录 1/1页
发现了个eclipse运行控制台的bug
发表在Java图书答疑
2020-03-10
《零基础学Java》第1章 初识Java
是否精华
是
否
版块置顶:
是
否
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
/*
* @百词斩(单词背记)
* @Test
* @QQ3462907欢迎交流
* @2020.3.9
* @用户直接输入回车或输入Q、q则程序结束。
* 英语是目前世界上使用最广泛的语言之一,也是国际上通用的语言。
* 随着各国交流越来越频繁,英语的地位与日俱增,在中国,已经有成
* 千上万的人加入到英语学习大军中,英语对于我们来说已经是一门不
* 可或缺的技能,但英语单词记忆是一大难题。请编写一个程序,帮助
* 学习者快速背记英语单词。运行程序,随机输出英语单词的汉语意思,
* 要求写出或说出英文。
* @2020.3.10
* 为百词斩程序添加提示功能和退出功能。运行程序,用户输入“?”号
* (中英文问好均可以)要求对单词进行提示,程序随机输出单词的前
* 两个字母或后两个字母进行提示。用户输入“q”或者“Q”,提示“正在
* 退出程序!!”并退出程序。
*/
public class Test {
public static void main(String[] args) {
Map<String, String> dic = new HashMap();
dic.put("柜台", "counter");
dic.put("售货摊", "stall");
dic.put("货架", "shelf");
dic.put("标价签", "price tag");
dic.put("打折扣", "discount");
dic.put("零钱", "change");
dic.put("银行", "bank");
dic.put("商店", "shop");
String word = "";// 正确答案
String inword = "";// 用户输入答案
List<String> list = new ArrayList(dic.keySet());// 单词库dic中Key的集合
String ranKey = "";// 单词库dic中的随机Key
System.out.println("===========百词斩===========\n");
Scanner in = new Scanner(System.in);
do {
ranKey = list.get((int) (Math.random() * list.size()));
if (dic.containsKey(ranKey)) {
word = dic.get(ranKey);
System.out.print(ranKey + ':');
try {
inword = in.nextLine();// 读取用户输入
} catch (Exception e) {
System.out.println(e.getMessage());
inword = "q";
}
while (inword.equals("?") || inword.equals("?")) {// 用户输入"?"则输出提示
{
char tips = '后';
String tipsWord = word.substring(word.length() - 2);
if (Math.random() > 0.5) {
tips = '前';
tipsWord = word.substring(0, 2);
}
System.out.println("提示:单词" + tips + "两个字母是:" + tipsWord);
System.out.print(ranKey + ':');
try {
inword = in.nextLine();// 读取用户输入
} catch (Exception e) {
System.out.println(e.getMessage());
inword = "q";
}
}
}
if (inword.equals("") || inword.equalsIgnoreCase("q")) {// 用户直接输入回车则结束程序
break;
} else if (inword.equalsIgnoreCase(word)) {// 不区分大小写比较两个字符串是否相等
System.out.println("√ 你真棒!");
} else {
System.out.println("⊗ 答错了,正确答案是:" + word);
System.out.println("加油啊!");
}
} else {
System.out.println("单词库错误,请检查后再运行!");
break;
}
} while (!inword.equals("") || inword.equalsIgnoreCase("q"));
in.close();
System.out.println("感谢使用“百词斩”系统,再见!");
}
}今天在运行上述代码时,输入“?”的过程中多按了几个键和鼠标,结果发现控制台没反应了,程序运行状态为红色,控制台不能输入字符,按什么键都没反应,过了一小会,控制台就出现了下面图片中显示的内容,不知道什么原因,应该是一个BUG吧。


购物车
发表新帖
立即签到







