我试图从 infile 中读取每个整数,并将其传递给 adScore 方法,该方法确定字母等级、所有等级的总数以及最高考试分数和最低考试分数。但是我在执行 for 循环时的 while 循环并没有从 infile 中提取数据,因为我在 for 循环执行 system.out.print 之后对其进行调试。返回的只是数字 0-29,这是我在循环中的计数器。可以帮助我了解我做错了什么,以便我可以从 infile 中提取成绩分数吗?
问候。
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
}
}
最佳答案
它打印 0 - 29,因为这就是你告诉它要做的事情:
System.out.println(""+i)
将打印出 i,它只是您用作循环计数器的整数。您实际上从未从 Scanner 对象中检索下一个值。我猜这是家庭作业,所以我不会给你任何代码,但我会说你肯定需要使用 Scanner 的 nextInt() 方法从输入文件中检索值并在你的文件中使用该值for循环。
关于java - 需要从 infile 中取出每个整数并将其传递给方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10158951/