I'm trying to write a small program to calculate certain grades, but I'm getting an inputMismatchException, but I don't know why. The problem is that I get the exception before I even had the chance to enter an integer.
Could somebody help me out.
public static void main(String[] args)
{
Scanner input = new Scanner("System.in");
int passes = 0;
int failures = 0;
int studentCounter = 1;
int result;
while(studentCounter <= 10)
{
//Zelf aangepast = output gewijzigd
System.out.println("Geef het resultaat in (1 = geslaagd, 2 = gebuisd).");
result = input.nextInt();
if(result == 1)
{
passes = passes + 1;
}
else
{
failures = failures + 1;
}
studentCounter = studentCounter + 1;
}
//Zelf aangepast = output gewijzigd
System.out.printf("Aantal leerlingen geslaagd: %d\nAantal leerlingen gebuisd: %d\n", passes, failures);
if(passes > 8)
{
//Zelf aangepast = output gewijzigd
System.out.println("Bonus voor de leerkracht!");
}
}
}
So as you can see I can't assign any number to the variable result.
result? What input did you provide that caused the exception to be thrown?