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