Assignment: #NearestSquares Due: 04/07/02019 Points: 3

Specification

The program prompts the user to enter a positive integer and reads the input into an int defined variable. This specification assumes the variable is named n.

Print an error message and exit the program if n is less than zero.

If n is a square number, print a message saying n is a square number along with its square root and exit the program.

Print the difference between n and its nearest square number that's less then n and the difference between n and its nearest square number that's greater than n. In addition, print the two nearest square numbers along with their respective square roots.

Example inputs/outputs. [Note: User inputs are in bold.]

   Enter a positive integer: 2001
   -65...24 [sqrt(1936)=44...sqrt(2025)=45]

   Enter a positive integer: 71
   -7...10 [sqrt(64)=8...sqrt(81)=9]

   Enter a positive integer: 16
   16 is a square number [sqrt(16)=4]

   Enter a positive integer: 213
   -17...12 [sqrt(196)=14...sqrt(225)=15]
Class Math

Docs.Oracle.com::class Math

Your program can use the sqrt(n) and floor(n) static methods defined in the Math class.

Your program is not allowed to use the Math.pow(n) static method.

Typecasting

The typecast operator () is used to change the data type of a variable when used in an expression.

Example typecast usages.

The argument n to Math.sqrt(n) is defined to be type double. If n is type int, then use a typecast.

   double y = Math.sqrt((int)n)

The return value of Math.floor(x) is defined to be type double. If the return value is to be assigned to a variable name n of type int, then use a typecast.

   int n = (int)Math.floor(y)