
Java program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value
- 12th May, 2019
- 12:12 PM
Challenge - Java program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value
Program
import java.util.Scanner;
import java.text.DecimalFormat;
import java.lang.*;
public class problem1 {
public static void main(String args[]) {
//taking inputs from user
Scanner sc=new Scanner(System.in);
System.out.println("Enter investment amount: ");
double i=sc.nextDouble();
System.out.println("Enter annual interest reate: ");
double a=sc.nextDouble();
System.out.println("Enter number of years: ");
double n=sc.nextDouble();
//defining DecimalFormat to round off result to 2 decimals
DecimalFormat twoDForm = new DecimalFormat("#.##");
//Displaying the result
System.out.println("Accumulated value is "+Double.valueOf(twoDForm.format(i*Math.pow(1+(a/1200),n*12))));
}
}