In: Computer Science
Create an Investment application that calculates how many years it will take for a $2,500 investment to be worth at least $5,000 if compounded annually at 7.5% ( Java Programming)
Java code:
public class Main{
public static void main(String[] args){
//initializing investment as
2500
double inv=2500;
//initializing year as
0
int year=0;
//looping till investment is
atleast 1
while(inv<5000){
//finding investment
inv=2500*Math.pow((1+7.5/100),year);
//incrementing year
year++;
}
//printing the number of
years required
System.out.println("Number of
years required is "+(year-1));
}
}
Screenshot:
Output: