In: Computer Science
JAVA
Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal.
For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%.
import java.util.Scanner;
public class Goal {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
//reading initial deposit
System.out.println("Enter initial
deposit: ");
double initial =
sc.nextDouble();
//reading target amount
System.out.println("Enter total
amount you want");
double amount =
sc.nextDouble();
int months = 0;
//loop until user reaches his
target
while (initial < amount) {
//adding 5%
interest rate
initial =
initial + initial * 0.05;
months++;
}
System.out.println("Years :
"+(months/12.0));
}
}
Note : If you like my answer please rate and help me it is very Imp for me