calculates the amount of years that it will take for a $2500 investment to be worth at least $5000 if compounded annually at 7.5% - Java File Path IO

Java examples for File Path IO:Scanner

Description

calculates the amount of years that it will take for a $2500 investment to be worth at least $5000 if compounded annually at 7.5%

Demo Code

import java.util.Scanner;

public class Investment {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    int Invest = 2500;
    int finalInvest = 5000;
    double currentInvest = Invest;

    double years = 1;

    while (currentInvest <= finalInvest) {
      years = years + 1;/*from w  w  w  .  j a v  a 2 s. c o  m*/
      currentInvest = currentInvest * 1.075;
    }
    System.out.println("It'll take you " + (int) years + " years");
  }

}

Related Tutorials