Improvement to the Program

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

If you asked for more accuracy than is possible in double precision variables, what might happen? For example, say that smallValue were 1.0E-21?

Answer:

The loop ends when it has achieved the goal. If the goal cannot be achieved, the loop might go on forever. Or, you might get lucky and accidentally reach the goal.

Improvement to the Program

Here is the familiar program fragment that asks the user to enter a floating point value:

    // get the number from the user
    Scanner scan = new Scanner( System.in );
    System.out.println("Enter the number:"); 
    N = scan.nextDouble();

Here is the program:


It would be nice if the user could enter number for which the square root is computed.

QUESTION 18:

(Mentally) copy the program fragment and paste it into the program so that the user can enter N.