Performing the Interest Calculations

The for statement (lines 16–23) executes its body 10 times, varying control variable year from 1 to 10 in increments of 1. This loop terminates when year becomes 11. (Variable year represents n in the problem statement.)

Classes provide methods that perform common tasks on objects. In fact, most methods must be called on a specific object. For example, to output text in Fig. C.15, line 13 calls method printf on the System.out object. Many classes also provide methods that perform common tasks and do not require objects. These are called static methods. For example, Java does not include an exponentiation operator, so the designers of Java’s Math class defined static method pow for raising a value to a power. ...

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.