So I am just making a simple averaging program for fun, and I came across an error that I am interested in why it's happening. Here's the code:
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);
}
}
}
}
And I'm getting Java.util.NoSuchElementException at all the places with scan.nextInt(). What's happening?