go to previous page   go to home page   go to next page hear noise

Answer:

No, because "yes" is not exactly equal to "y" . A better program would test for this response, also.


Reading the User's Response

Here is the program with some additional work done on the "prompting and looping" aspect. The program is written so that the loop body always executes at least once. In its first execution, it asks the user for x and prints out the value of the polynomial. Then, at the bottom of the loop, it asks if it should continue.

Review (of Chapter 10): the next() method of Scanner returns the next token in the input stream. By default, a token is a group of characters surrounded by white space.

import java.util.Scanner ;

class EvalPoly
{
  public static void main (String[] args ) 
  {
   
    Scanner scan = new Scanner ( System.in );

    double x;                      // a value to use with the polynomial
    String response = "y";         // "y" or "n"

    while ( response.equals( "y" ) )    
    {
       // Get a value for x

       // Evaluate the polynomial

       // Print out the result

       // Ask the user if the program should continue.
       // The user's answer is "response".
       ;

       response = scan.;      
    }

  }
}


QUESTION 17:

Fill in the blanks.