线程" main"中的例外情况java.util.Scanner中

时间:2017-11-15 05:19:45

标签: loops

function theHunt($node)
{
    foreach ($node->children() as $child);
    {
        if (isset($child))
        { //has children
          theHunt($child); //go one level down
        }
        else
        { //this is a child
          //enum thru its attributes
        }
    }
}

当我运行我的代码时,我的第一个循环通过我的扫描仪,但后来我遇到了错误。我不确定自己做错了什么?我需要循环,直到10个问题得到正确回答,20个回答总体,或者正确答案的平均值超过85%。

What is the result?
10 - 7 =
3
Congratulations, you got it correct!
Exception in thread "main" What is the result?
9 + 8 =
java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at proj3.Project4App.main(Project4App.java:28)

}

1 个答案:

答案 0 :(得分:0)

Scanner scan = new Scanner(System.in);带出您的周期。对scan.close;执行相同的操作,在退出main函数之前将其正确放置。当您close Scanner时,它也会关闭其来源。这可能是你例外的原因。