Performing the Interest Calculations with static Method pow of Class Math

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. 5.6, line 13 calls method printf on the System.out object. Some classes also provide methods that perform common tasks and do not require you to first create objects of those classes. These are called static methods. For example, Java does not include an exponentiation operator, so the designers of ...

Get Java™ How To Program (Early Objects), Tenth 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.