Page 1163 - AP Computer Science A, 7th edition
P. 1163

Chapter 9. The AP Computer S cience A Labs
ANSWERS EXPLAINED
1. (C) Segment III works because if you enter an age of 90, say, category will correctly be assigned “Senior”, and none of the other else pieces of code will be executed. Similarly, if you enter an age corresponding to an adult or a child, only the correct assignment is made. Segment I fails because if you enter an age of 90, category will be assigned “Senior”, but then will be changed to “Adult” when the age passes the second test. Segment II uses incorrect syntax. The segment will work if you change the second test to
if (age >= 18 && age <= 64)
  






























































































   1161   1162   1163   1164   1165