为了完成我应该做的作业,我和我的小组被要求编写一款教育/互动游戏,我们决定进行一项基础数学游戏。
为了获得用户的答案,我们决定使用Java Scanner并将这一行代码放在我们拥有的所有代码的顶部;
java.util.Scanner
使用此功能的循环之一是上面有问题的页面,循环看起来像这样。
scoreCount = 0;
for (questions = 0; questions < 5;) {
//get the user's answer
userAnswer[questions] = input.nextInt();
//text box for users answer
if (userAnswer[questions] == compAnswer) {
//put tick next to answer
//add one to score
scoreCount = scoreCount + 1;
} else if (userAnswer[questions] != compAnswer) {
//put cross next to answer
}
//go to next question
questions++ ;
}
我正在处理所有引发的错误,每次我没有java.util.Scanner
注释掉时,Processing都会向我们抛出错误unexpected token:
,然后是class
or void
,我没有得到,但是当java.util.Scanner
被注释掉时,所有类和void都会消失工作,并且.input.nextInt()
未被识别。
我是Java编程和处理的新手,对您的任何帮助将不胜感激
编辑
我认为这是让您查看我的代码的链接,它称为Test;
您必须检查扫描仪是否具有下一个int(令牌)
Scanner input = new Scanner(System.in);
.
.
if(input.hasNextInt()) { // or hasNext()
userAnswer[questions] = input.nextInt();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句