Why is this loop a sentinel-controlled loop?
The sentinel value "n" terminates the loop.
Here is the program, with some work done on reading a value for "x". (Look in Chapter 11 to review floating point input.)
import java.io.*;
class evalPoly
{
public static void main (String[] args ) throws IOException
{
BufferedReader userin =
new BufferedReader(new InputStreamReader(System.in) );
String xChars; // character version of x, from the user
double x; // a value to use with the polynomial
String response = "y"; // "y" or "n"
while ( response.equals( "y" ) )
{
// Get a value for x.
__________________________________________ ;
__________________________________________ ;
// convert data in character form to floating point form
x = Double.parseDouble( xChars );
// Evaluate the polynomial.
// Print out the result.
// Ask the user if the program should continue.
System.out.println("continue (y or n)?");
response = userin.readLine();
}
}
}