Absolutely NOT! That's 80 years without chocolate-chip cookies!
We obviously need to find a bank with an interest rate higher than five percent. Say that you are willing to wait 40 years for your million dollars. How high must the interst rate be?
One way to answer this question is to try out various interest rates until you find one that works. Here is a program that does that:
import java.io.*; class dollarsAfterForty { public static void main( String[] args ) throws IOException { double dollars = 1000.00 ; double rate; int year = 1 ; // get the interest rate from the user String rateChars; BufferedReader stdin = new BufferedReader( __________________________ ); System.out.println("Enter the interest rate in percent:"); rateChars = _____________________ ; rate = Double.parseDouble( rateChars ); // get rate in percent rate = _________________; // convert percent to decimal fraction while ( year <= 40 ) { // add another year's interest dollars = dollars + dollars * _________________ ; // add in this year's contribution dollars = dollars + 1000 ; year = year + 1 ; } System.out.println("After 40 years at " + rate*100 + " percent interest you will have " + dollars + " dollars" ); } }
This program does NOT use a result-controlled loop.
It uses a counting loop because the counter, year
,
is used to control the loop.