【发布时间】:2013-12-04 07:23:18
【问题描述】:
我正在尝试从外部文件中读取。我已经成功地从文件中读取,但现在我有一个小问题。该文件包含大约 88 个动词。动词是这样写在文件中的: 曾经是 打打打打 成为 成为 成为 等等……
我现在需要帮助的是我想要一个类似程序的测验,其中只会出现两个来自动词的随机字符串,并且用户必须填写缺少的那个。我想要这个(“------”),而不是丢失的那个。我的英语不太好,所以我希望你明白我的意思。
System.out.println("Welcome to the programe which will test you in english verbs!");
System.out.println("You can choose to be tested in up to 88.");
System.out.println("In the end of the programe you will get a percentage of total right answers.");
Scanner in = new Scanner(System.in);
System.out.println("Do you want to try??yes/no");
String a = in.nextLine();
if (a.equals("yes")) {
System.out.println("Please enter the name of the file you want to choose: ");
} else {
System.out.println("Programe is ended!");
}
String b = in.nextLine();
while(!b.equals("verb.txt")){
System.out.println("You entered wrong name, please try again!");
b = in.nextLine();
}
System.out.println("How many verbs do you want to be tested in?: ");
int totalVerb = in.nextInt();
in.nextLine();
String filename = "verb.txt";
File textFile = new File(filename);
Scanner input = new Scanner(textFile);
for (int i = 1; i <= totalVerb; i++){
String line = input.nextLine();
System.out.println(line);
System.out.println("Please fill inn the missing verb: ");
in.next();
}
System.out.println("Please enter your name: ");
in.next();
【问题讨论】:
-
更具体一些,你不能做什么?我们不想运行您的代码来弄清楚。
-
您要检查文件中是否存在动词或其他东西吗?
-
我现在需要帮助的是我想要一个类似程序的测验,其中只会出现来自动词的两个随机字符串,并且用户必须填写缺少的那个。我想要这个(“------”),而不是丢失的那个。
-
是这样吗,每行有3个动词(现在,过去,分词),你想显示这三个中的任何两个,用户必须填写第三个。???跨度>
-
“动词中的字符串”是什么意思?我不太明白。