New Example

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:

No, probably not.

New Example

Sometimes the user is asked explicitly if the loop should continue. The user enters "yes" or "no" (or maybe "y" or "n"). Now the sentinel is of type String or char. The next example illustrates this: Say that you are interested in the value of the polynomial:

7x3- 3x2 + 4x - 12

for various values of x. The value x is a double precision value. For example, when x == 2.0 the polynomial is equal to:

7*23- 3*22 + 4*2 - 12 = 7*8 - 3*4 + 8 - 12 = 40

The program lets the user enter various values for x and see the result for each one.

QUESTION 15:

Would using a special value of x (such as 0.0) as a sentinel work well in this program?