I am attempting to read each integer from an infile and passing that on to the method adScore which determines the letter grade, and total count of all the grades and the highest exam score and lowest exam score. But my while loop when doing the for loop isn’t pulling in the data from the infile as I am debugging it after the for loop doing a system.out.print. And what returns are just the numbers 0-29 which is my counter in the loop. Can assist me as to what I am doing wrong so that I can pull in the grade scores from the infile?
Regards.
while(infile.hasNextInt())
{
for(int i=0; i <30; i++)//<-- it keeps looping and not pulling the integers from the file.
{
System.out.println(""+i);//<--- I placed this here to test what it is pulling in and it is just counting
//the numbers 0-29 and printing them out. How do I get each data from the infile to store
exam.adScore(i);//determines the count of A, B, C, D, F grades, total count, min and max
}
}
Tron’s right — you haven’t actually asked the scanner to read the next integer.
Scanner.hasNextInt()simply tests to see if there’s an integer to be read. You’re just tellingito loop through the values 0-29. I think you mean to do something like this:If you’re not sure that every line in the input is an integer, you could do something like this: