Method incrementLetterGradeCounter
Method incrementLetterGradeCounter
contains a switch
statement (lines 72–94) that determines which counter to increment. We assume that the user enters a valid grade in the range 0–100. A grade in the range 90–100 represents A, 80–89 represents B, 70–79 represents C, 60–69 represents D and 0–59 represents F. The switch
statement consists of a block that contains a sequence of case labels and an optional default case. These are used in this example to determine which counter to increment based on the grade.
When the flow of control reaches the switch
, the program evaluates the expression in the parentheses (grade / 10
) following keyword switch
. This is the switch
’s controlling expression. The program compares ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.