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

What is 0.00000000000001 in scientific notation?

Answer:

1.0E-14


Skeleton Square Root Program

Here is a skeleton of the program, with the loop ending condition translated from math into Java. The absolute value of a double is calculated by Math.abs(double). The skeleton contains the result-controlled loop. All you need to do is fill in the calculation part. You can do this with a single assignment statement.

The formula for updating the guess is:

        newGuess = N/(2*oldGuess) + oldGuess/2

In an assignment statement, first the value on the right of the = is calculated. Then that value is copied to the variable on the left. When you translate the formula into Java, you can use this fact to do the translation using a single variable, guess.


class  SquareRoot
{
  public static void main( String[] args ) 
  {
    final double smallValue = 1.0E-14 ;
    double N     = 3.00 ;
    double guess = 1.00 ;

    while ( Math.abs( N/(guess*guess) - 1.0 ) > smallValue )
    {

       // calculate a new value for the guess
       
       
    }

    System.out.println("The square root of " + N + " is " + guess ) ;
  }

}

QUESTION 16:

Complete the program by filling in the loop body. Type in your answer into the text area.