Write a Java method to compute the future investment value at a given interest rate for a
specified number of years.
Input the investment amount: 1000
Input the rate of interest: 10
Input number of years: 5
Years FutureValue
1 1104.71
2 1220.39
3 1348.18
4 1489.35
5 1645.31
package interest;
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
System.out.printf("Input the investment amount: ");
Scanner scan = new Scanner(System.in);
double amount = scan.nextDouble();
System.out.printf("\nInput the rate of interest: ");
double rate = scan.nextDouble() * 0.01;
System.out.printf("\nInput number of years: ");
int years = scan.nextInt();
System.out.printf("\nYears FutureValue ");
for(int i=1; i<=years; i++){
double interest = (amount * rate * i);
double total = amount + interest;
System.out.printf("\n"+total);
amount = total;
System.out.printf("\n%d\t %f ", (i), total);
}
}
}
Comments
Leave a comment