Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. package project2Package;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6. This program demonstrates a for loop with symmetric bounds (i.e. 1 <= year <= nyears)
  7. */
  8. public class InvestmentTable {
  9. public static void main (String[] args)
  10. {
  11. final double RATE = 5;
  12. final double INITIAL_BALANCE = 3000;
  13. double balance = INITIAL_BALANCE + 12000;
  14.  
  15. System.out.print("Years for investment: ");
  16. Scanner in = new Scanner(System.in);
  17. int nyears = in.nextInt();
  18.  
  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.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement