0
public class BarChart // Modified from Fig 7.6
{
public static void main(String[] args)
{
int[] grades = {90, 71, 89, 75, 83, 87, 81, 100, 99, 83,
65, 100, 91, 78, 88, 62, 55, 84, 73, 89}; // 20 elements
int[] frequency = new int[11]; // 11 ranges
System.out.println("Grade distribution:");
for (int i = 0; i < grades.length; i++) {
frequency[grades[i]/10]++; //How does this work? why does it say 10
}
for (int i = 0; i < frequency.length; i++)
{
if (i == 10) {
System.out.printf("%5d: ", 100);
}
else {
System.out.printf("%02d-%02d: ", i * 10, i * 10 + 9);
}
for (int stars = 0; stars < frequency[i]; stars++) { // How does it know where to print the stars?
System.out.print("*");
}
System.out.println();
}
}
}
출력 : 나는 문제가이 프로그램이 어떻게 작동하는지 이해하는 데이 배열은이 barchart를 어떻게 인쇄합니까?
. 좀 더 명확한 답을 얻기 위해 몇 가지 질문을 코멘트로 넣었습니다. 출력물도 첨부했습니다.
'등급 [내가]/10'은 10으로 등급을 나누고 코드 –
을 reindent하시기 바랍니다 ... 그리고'printf' 문은 조건부을 인쇄 특정 수의 별. 디버거에 액세스 할 수있는 경우이 코드를 단계별로 실행하여 작동 방식을 확인하는 것이 좋습니다. –
내가 틀렸다고 정정하되 StackOverflow가 다른 사람들의 코드를 설명하는 플랫폼이 아닙니다. 사소한 의견 : ** 코드 들여 쓰기 **를 사용하여 프로그램 구조 전달 – AKSW