Guest User

Untitled

a guest
Nov 21st, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class capital {
  5. public static void main(String[] args) {
  6.  
  7. /*
  8. Write a program that calculates accumulated capital for n years based on the following formula:
  9. capital = capital + interestRate * capital / 100
  10. An example:
  11. Initial capital: 100
  12. Interest rate: 1.7
  13. How many years(n)?: 4
  14. YEAR CAPITAL
  15. 1 101.70
  16. 2 103.43
  17. 3 105.19
  18. 4 106.98
  19. */
  20. Scanner input = new Scanner(System.in);
  21.  
  22. System.out.println("Enter starting capital");
  23. double startingCapital = input.nextDouble();
  24. System.out.println("Enter interest rate");
  25. double interestRate = input.nextDouble();
  26. System.out.println("Enter number of years");
  27. int years = input.nextInt();
  28. int raisedto = 1;
  29. System.out.println("Year capital");
  30. for (int start = 1; start <= years; start++) {
  31. double sum = startingCapital + Math.pow((interestRate * startingCapital / 100), raisedto);
  32. raisedto++;
  33. System.out.println(start+ ". " + sum);
  34. }
  35.  
  36.  
  37. }
  38.  
  39. }
Add Comment
Please, Sign In to add comment