我想從外部文件讀取。我已經成功完成了從文件讀取,但現在我有一個小問題。該文件包含大約88個動詞。動詞都寫在文件中是這樣的:be was been beat beat beaten become became become
等等...數組/串的建議,隨機
我現在需要的是,我要像程序的測驗,其中只有兩個由動詞隨機串上來了,並且用戶有填寫缺失的那個。而不是一個缺少的,我想這(「------」)。我的英文不是很好。所以我希望你明白我的意思。
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();
有:「兩個stringsfrom動詞」你的意思是動詞的兩個不同的時態,用戶必須輸入第三緊張,對不對? – kai
右啓。隨機地,其中一個將會有「-----」。 – user3012649