Problem

Playing CompilerDetermine whether or not each of the following classes compiles, and if no...

Playing Compiler

Determine whether or not each of the following classes compiles, and if not, fix the errors. Each class should compute the square root of 122.0.

a. public class Test

   {      public static void main(String[] args)      {         float x = (float) 122.0;         float newGuess = (float) 1.0;         float oldGuess = x;         // This code computes the square root of x;         try         {            while (oldGuess != newGuess) {            oldGuess = newGuess;            newGuess = (float) (x/oldGuess = oldGuess)/ (float) 2.0;            System.out.println(oldGuess);            System.out.println(newGuess);         }            // Keep improving the guess until two consecutive guesses are equal         catch         {            System.out.println("Did not work");         }      }   }


b. public class Test   {      public static void main(String[] args) throws ArithmeticException      {         float x = (float) 122.0;         float newGuess = (float) 1.;         float oldGuess = x;         // This code computes the square root of x;         try         {            while (oldGuess != newGuess) {            oldGuess = newGuess;            newGuess = (float) (x/oldGuess = oldGuess)/ (float) 2.0;            System.out.println(oldGuess);            System.out.println(newGuess);         }            // Keep improving the guess until two consecutive guesses are equal         finally {}      }   }


c. public class Test   {      public static void main(String[] args) throws ArithmeticException      {        float x = (float) 122.0;        float newGuess = (float) 1;        float oldGuess = x;        // This code computes the square root of x;        try        {          while (oldGuess != newGuess)          {             oldGuess = newGuess;             newGuess = (float) (x/oldGuess = oldGuess)/ (float) 2.0;             System.out.println(oldGuess);             System.out.println(newGuess);          }            // Keep improving the guess until two consecutive guesses are equal        }          catch (Arithmetic Exception e)          {             System.out.println("Bad division in algorithm");          }      }   }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT