Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class capital {
- public static void main(String[] args) {
- /*
- Write a program that calculates accumulated capital for n years based on the following formula:
- capital = capital + interestRate * capital / 100
- An example:
- Initial capital: 100
- Interest rate: 1.7
- How many years(n)?: 4
- YEAR CAPITAL
- 1 101.70
- 2 103.43
- 3 105.19
- 4 106.98
- */
- Scanner input = new Scanner(System.in);
- System.out.println("Enter starting capital");
- double startingCapital = input.nextDouble();
- System.out.println("Enter interest rate");
- double interestRate = input.nextDouble();
- System.out.println("Enter number of years");
- int years = input.nextInt();
- int raisedto = 1;
- System.out.println("Year capital");
- for (int start = 1; start <= years; start++) {
- double sum = startingCapital + Math.pow((interestRate * startingCapital / 100), raisedto);
- raisedto++;
- System.out.println(start+ ". " + sum);
- }
- }
- }
Add Comment
Please, Sign In to add comment