Absolute Java (6th Edition)
Absolute Java (6th Edition)
6th Edition
ISBN: 9780134041674
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 2, Problem 1PP

The Babylonian algorithm to compute the square root of a positive number « is as follows:

1. Make a guess at the answer (you can pick n/2 as your initial guess).

2 . Computer = n / guess 3 . Set guess = guess + r / 2

4. Go back to step 2 for as many iterations as necessary. The more you repeat steps 2 and 3, the closer guess will become to the square root of n.

Write a program that inputs a double for n, iterates through the Babylonian algorithm five times, and outputs the answer as a double to two decimal places. Your answer will be most accurate for small values of n.

Blurred answer
Students have asked these similar questions
The Babylonian algorithm to compute the square root of a positive number n is asfollows:1. Make a guess at the answer (you can pick n/2 as your initial guess).2. Compute r = n / guess3. Set guess = (guess +r)/ 24. Go back to step 2 for as many iterations as necessary. The more you repeat steps2 and 3, the closer guess will become to the square root of n. Write a program that inputs a double for n, iterates through the Babylonian algo-rithm five times, and outputs the answer as a double to two decimal places. Your answer will be most accurate for small values of n.
...
Make a program that asks for a width, and then prints a pyramid of that width. The pyramid must be of odd width, and if the user enters an even number the program should print "Please enter an odd number" and ask again. (It is ok if the program gives an error if the user enters a non-number).  Example: Please enter the pyramid width 10Please enter an odd numberPlease enter the pyramid width 14Please enter an odd numberPlease enter the pyramid width 13      *     ***    *****   *******  ********* ************************   The first line should have 1 asterisk, the second 3, then 5, 7, 9 etc. The number of spaces before starting the asterisks is  (n−i)/2 Where n is the width of the pyramid and i is the number of asterixes in the current line. Note that this is always a whole number, as n and i are odd and hence (n-i) is even.

Chapter 2 Solutions

Absolute Java (6th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY