扫描程序的noSuchElementException

时间:2014-01-16 19:49:51

标签: java

所以我只是制作一个简单的平均程序以获得乐趣,我遇到了一个错误,我感兴趣的是它为什么会发生。这是代码:

import java.util.Scanner;

class Main
{
public static Scanner scan = new Scanner(System.in);
public static void main (String[] args)
{
    System.out.println("how many #s to average");
    int bob = 0;

    int loop = scan.nextInt();
    int counter = 0;
        while(counter<loop){
        counter++;
        int one = scan.nextInt();
        int two = scan.nextInt();
        bob = bob+one+two;
        if(loop==counter){
        System.out.println("The average is "+bob);
    }
    }

}
}

我在scan.nextInt()的所有地方都得到了Java.util.NoSuchElementException。发生了什么事?

0 个答案:

没有答案