Java Reference
In-Depth Information
70 private int years;
71 }
ch06/invest2/InvestmentRunner.java
1 /**
>2This program computes how much an investment grows in
3a given number of years.
4 */
5 public class InvestmentRunner
6 {
7 public static void main(String[] args)
8 {
9 final double INITIAL_BALANCE = 10000;
10 final double RATE = 5;
11 final int YEARS = 20;
12 Investment invest = new
Investment(INITIAL_BALANCE, RATE);
13 invest.waitYears(YEARS);
14 double balance = invest.getBalance();
15 System.out.printf(ÐThe balance after
%d years is %.2f\nÑ,
16 YEARS, balance);
17 }
18 }
Output
The balance after 20 years is 26532.98
240
241
S ELF C HECK
3. Rewrite the for loop in the waitYears method as a while loop.
4. How many times does the following for loop execute?
for (i = 0; i <= 10; i++)
System.out.println(i * i);
Search WWH ::




Custom Search