无法确定文本文件读入程序(java)中的各种元素
我很难确定如何以可用的方式拆分文本文件中的各个元素。我的程序意味着在一个文本文件中读取一个arraylist,显示可能的答案,询问答案,只有在给出正确答案时才继续。问题是,文本文件必须有不同数量的答案,因此没有数字方法来确定何时在文本文件中找到问题以及有多少问题。以下是测验文本文件的示例:
要舔几下才能到达tootsie pop的tootsie roll中心?(问题)
4(分配给正确答案的数值)
(可能的答案)
一个
两个
三
四
你叫什么名字
三,
亚瑟,英国国王
勇敢的兰斯洛特爵士
罗宾爵士不如兰斯洛特爵士勇敢
谁先上
五,
什么
为什么
因为
谁
我不知道
我讨厌问你们这样一个大的逻辑问题,但我真的被困在这个问题上了。 这是我的密码:
import java.util.*;
import java.io.*;
public class JavaApplication8 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
Scanner inScan = new Scanner(System.in);
String file_name;
System.out.print("What is the full file path name?\n>>");
file_name = inScan.next();
Scanner fScan = new Scanner(new File(file_name));
ArrayList<String> Questions = new ArrayList();
while (fScan.hasNextLine())
{
Questions.add(fScan.nextLine());
}
System.out.println(Questions.get(0));
System.out.println(Questions.get(2));
System.out.println(Questions.get(3));
System.out.println(Questions.get(4));
System.out.println(Questions.get(5));
String guess;
System.out.print("What is your answer?\n>>");
guess = inScan.next();
if (guess == Questions.get(1))
{
System.out.println("Correct");
}
else
System.out.println("Incorrect");
}
**我没有为其他问题编写代码,只是第一个问题
# 1 楼答案
问号
?
的唯一例子似乎是当有问题时。测试文件中的每一行,看看该行中是否有问号。如果是这样,那么这就是一个新的问题/答案集