Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project2Package;
- import java.util.Scanner;
- /**
- This program demonstrates a for loop with symmetric bounds (i.e. 1 <= year <= nyears)
- */
- public class InvestmentTable {
- public static void main (String[] args)
- {
- final double RATE = 5;
- final double INITIAL_BALANCE = 3000;
- double balance = INITIAL_BALANCE + 12000;
- System.out.print("Years for investment: ");
- Scanner in = new Scanner(System.in);
- int nyears = in.nextInt();
- for (int year = 1; year <= nyears; year++)
- {
- double interest = balance * RATE / 100;
- balance = balance + interest;
- System.out.printf("%4d %10.2f\n", year, balance);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement