我有一个关于第三个循环的问题,请问它是如何工作的?第三个for循环如何工作?
public void outputBarChart()
{
System.out.println("Grade Distribution: \n");
int frequency[] = new int[11];
for(int oneGrade : grade)
{
++frequency[oneGrade/10];
}
for (int count = 0; count < frequency.length; count++)
{
if (count == 10) {
System.out.println("100");
}
else {
System.out.printf("%02d-%02d: ",
count*10, count*10 + 9);
}
//the third for loop here !
for (int star = 0; star < frequency[count]; star++){
System.out.print("*");
}
System.out.println();
}
}
问题是我不知道它是如何打印出明星的机制。
你能明确你的困惑吗?它只是在连续打印频率[count]'星星 –
你不明白什么?这是一个简单的for循环,每次迭代都会打印一个'*'。 –
运行调试器,跟踪执行并查看会发生什么。 –