Java Reference
In-Depth Information
Read name of bridge
If not OK, exit loop
Read length of bridge in feet
If not OK, exit loop
Convert length to meters
Print bridge data
}
Use a Boolean variable, a break statement, and a method with multiple
return statements. Which of these three approaches do you find
clearest?
΢ Exercise R6.8 Implement a loop that prompts a user to enter a number
between 1 and 10, giving three tries to get it right.
΢ Exercise R6.9 Sometimes students write programs with instructions such
as ȒEnter data, 0 to quitȓ and that exit the data entry loop when the user
enters the number 0. Explain why that is usually a poor idea.
277
278
΢ Exercise R6.10. How would you use a random number generator to
simulate the drawing of a playing card?
΢ Exercise R6.11. What is an Ȓoff-by-one errorȓ? Give an example from
your own programming experience.
΢΢ Exercise R6.12. Give an example of a for loop in which symmetric
bounds are more natural. Give an example of a for loop in which
asymmetric bounds are more natural.
΢ Exercise R6.13 What are nested loops? Give an example where a nested
loop is typically used.
΢T Exercise R6.14 Explain the differences between these debugger operations:
ȗ
Stepping into a method
ȗ
Stepping over a method
΢΢T Exercise R6.15 Explain in detail how to inspect the string stored in a
String object in your debugger.
Search WWH ::




Custom Search