【发布时间】:2015-01-29 01:22:02
【问题描述】:
我在使用 扫描仪文件 = 新扫描仪(文件路径); 我的文件是这样组织的
问题 x.y
答案1
答案2
答案3
答案4
提示:提示问题 x.y 级别 z Genere t
我对 java 很陌生,在我使用过的所有项目中 .next(字符串模式) 返回一个包含 parrtern 并到达行尾的字符串,但我继续得到不匹配异常.. 我真的不明白什么 https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html 定义为令牌,因此我不知道如何处理它..
我的代码是
public Question getQuestion(String filePath)
{
ArrayList questions = new ArrayList();
Scanner file = new Scanner(filePath);
String questionInFile = "Question";
while(file.hasNextLine())
questions.add(questionInFile+file.next(questionInFile));
Random rg = new Random();
String Q = (String)questions.get(rg.nextInt(10)+1);
file.close();
ArrayList<String> answer=getAnswers(filePath, Q);
String correctAnswer=answer.get(0);
return new Question(Q, answer, correctAnswer);
}
【问题讨论】:
标签: file java.util.scanner next inputmismatchexception