The loop (and the program) stops because the user did not type "y".
The program is not as user friendly as we would like. It insists that the user enter exactly "y" to continue.
This problem could be fixed with a few extra statements
and some methods of String
objects (see chapter 44.)
But let's not.
Here is a sample user dialog with the program:
C:\users\default\JavaLessons\chap18>java EvalPoly Enter a value for x: -1 The value of the polynomial at x = -1.0 is: -26.0 continue (y or n)? y Enter a value for x: 1 The value of the polynomial at x = 1.0 is: -4.0 continue (y or n)? y Enter a value for x: 1.178 The value of the polynomial at x = 1.178 is: -0.008209736000004852 continue (y or n)? yes C:\users\default\JavaLessons\chap18>
The user entered "yes" at the end, but that did not match "y" so the program ended.
At about what value for x does the polynomial evaluate to zero?