Investment Calculator

Run Settings
LanguageJava
Language Version
Run Command
import java.util.Scanner; import java.text.DecimalFormat; class CD { public static void main(String[] args) { double InitalInvestment; int Interestrate; double DesiredEndingValue; DecimalFormat df = new DecimalFormat("#%"); // Scanner Input Scanner scan = new Scanner (System.in); // Inital Investment System.out.print (" Please Enter the inital investment: "); InitalInvestment = scan.nextDouble(); System.out.print (InitalInvestment); // Interest Rate System.out.print ("\n Pleae Enter Interest Rate (as a decimal): "); //String = userinput; Interestrate = scan.nextInt(); System.out.print (df.format (Interestrate)); // Desired Ending Value System.out.print (" \n Please Enter Desired Ending Value: "); DesiredEndingValue = scan.nextDouble(); System.out.print (DesiredEndingValue); // loop and year counter int counter =0; do { InitalInvestment = InitalInvestment + (InitalInvestment * Interestrate); counter++; } while ( InitalInvestment < DesiredEndingValue); // Output System.out.println(" \n Number of years until desired value: " + counter + " years"); } }
Editor Settings
Theme
Key bindings
Full width
Lines