Example Output

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

Will the program work if the user enters a zero?

Answer:

It should, since zero has a square root.

Example Output

It is good to get into the habit of worrying about what happens with special values. The program does happen to work with zero. Here is the output of the program for several other values:

C:/chap19>java SquareRoot
Enter the number: 0.0000000000000000000003
The square root of 3.0E-22 is 1.732050807568877E-11

C:/chap19>java SquareRoot
Enter the number: -12
Please enter a positive number

C:/chap19>java SquareRoot
Enter the number: 144.0
The square root of 144.0 is 12.0

QUESTION 22:

Suggest a few other values with which the program should be tested.