The completed program is given below.
Here is the complete program.
class millionDollarYears
{
public static void main( String[] args )
{
double dollars = 1000.00 ;
int year = 0;
while ( dollars < 1000000.00 )
{
// add another year's interest
dollars = dollars + dollars*0.05;
year = year + 1;
}
System.out.println("It took " + year + " years to reach your goal.");
}
}
|
It is not a counting loop, because the loop is being controlled by the result of a calculation. Only when the result reaches a goal is the loop finished. The variable year is a counter, but it is not controlling the loop.