1 import java.util.Scanner;
2
3 /**
4 This program prints a table showing the growth of an investment.
5 */
6 public class InvestmentTable
7 {
8 public static void main(String[] args)
9 {
10 final double RATE = 5;
11 final double INITIAL_BALANCE = 10000;
12 double balance = INITIAL_BALANCE;
13
14 System.out.print("Enter number of years: ");
15 Scanner in = new Scanner(System.in);
16 int nyears = in.nextInt();
17
18 // Print the table of balances for each year
19
20 for (int year = 1; year <= nyears; year++)
21 {
22 double interest = balance * RATE / 100;
23 balance = balance + interest;
24 System.out.printf("%4d %10.2f\n", year, balance);
25 }
26 }
27 }