The Gloomy News

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

It is not a sentinel controlled loop because there is no data being read in that contains a sentinel.

The Gloomy News

How many years does it take to reach a million dollars? 142

It might be that you do not wish to wait that long. After examining your lifestyle, you decide to give up your expensive chocolate-chip cookie habit and now can put an extra $1000 into your bank account at the end of every year. Now how long will it take to reach your million dollar goal?

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 ; 

      // add in this year's contribution
       ;

      year    =  year + 1 ;
    }

    System.out.println("It took " + year + " years to reach your goal.");
  }

}

 

QUESTION 5:

Fill in the bank.... err, blank.