我写了一个做不同事情的类。我正在尝试使用循环来计算数组列表中的用户数。基本上,班级正在获取信息并添加有关学生的信息。输入的内容之一是学生所学的学分。假设我在我的数组列表中输入了 5 个学生。两个学生修了 5 个学分 2 个学生修了 6 个学分,最后一个学生修了 9 个学分。我在课堂上创建了一些代码,假设用户想知道数组中有多少学生正在学习 6 个学分。所以我创建了一个段,让用户输入该数字,班级将在数组中查找并返回有多少学生正在使用该数字,但它不起作用。我不知道这是否有意义
System.out.print("Please enter a number of credits:\n");
inputInfo = stdin.readLine().trim();
int credits = Integer.parseInt(inputInfo);
int count = 0;
for (int i = 0; i < studentList.size(); ++i)
{
count++;
}
System.out.println("The number of students who are taking " + credits
+ " credits is: " + count);
break;