Exercises

  1. 4.10 Compare and contrast the if single-selection statement and the while repetition statement. How are these two statements similar? How are they different?

  2. 4.11 Explain what happens when a Java program attempts to divide one integer by another. What happens to the fractional part of the calculation? How can you avoid that outcome?

  3. 4.12 Describe the two ways in which control statements can be combined.

  4. 4.13 What type of repetition would be appropriate for calculating the sum of the first 100 positive integers? What type would be appropriate for calculating the sum of an arbitrary number of positive integers? Briefly describe how each of these tasks could be performed.

  5. 4.14 What is the difference between preincrementing ...

Get Java How to Program (early objects), 9/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.