Finding Average Grades : for « JSP « Java Tutorial






<HTML>
  <HEAD>
    <TITLE>Finding Average Grades</TITLE>
  </HEAD>

  <BODY>
    <H1>Finding Average Grades</H1>
    <%
        double grades[] = {8, 9, 7, 6, 5, 4};
        double sum, average;

        sum = 0;

        for (int i = 0; i < grades.length; i++) {
            sum += grades[i];
        }

        average = sum / grades.length;

        out.println("Average grade = " + average);
    %>
  </BODY>
</HTML>








23.8.for
23.8.1.Using the for Statement
23.8.2.Finding Average Grades
23.8.3.Using Two Loop Indexes
23.8.4.Your for statement to loop through an array