0% found this document useful (0 votes)
113 views

Java Babylonian Algorithm. The Babylonian Algorith...

Uploaded by

Hadiqa Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

Java Babylonian Algorithm. The Babylonian Algorith...

Uploaded by

Hadiqa Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

10/27/2020 Java Babylonian Algorithm. The Babylonian Algorith... | Chegg.

com

 
NEW!
Textbook Solutions Expert Q&A Study Pack Practice  

Find solutions for your homework Search

home / study / engineering / computer science / computer science questions and answers / java babylonian algorithm. the babylonian algorithm to
t…c

com…
Question: Java Babylonian Algorithm. The Babylonian algorithm to comput Post a question
Answers from our experts for your tough
homework questions
See this question in the app
Enter question

Java
Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as
follows: Continue to post
      1. Make a guess at the answer (you can pick n/2 as your initial guess).
20 questions remaining
      2. Computer = n / guess.
      3. Set guess = (guess +r) / 2
2.
      4. Go back to step 2 until the last two guess values are within 1% of each other.
Write a program that inputs an integer for n, iterates through the Babylonian algorithm until the guess is
Snap a photo from your
within 1% of the previous guess, and outputs the answer as a double to two decimal places. Your answer
should be accurate even for large values of n. phone to post a question
We'll send you a one-time download
INPUT and PROMPTS. The program prints "This program estimates square roots." and then prompts for a link
positive integer as follows: ("Enter an integer to estimate the square root of: " and then reads in the integer.
OUTPUT. Each time a new guess is computed, the program prints the line "Current guess: g", where g is
the current guess, printed out with no special formatting. The nal output is "The estimated square root of 888-888-8888 Text me
x is y", where x is the integer that was read in and y is the value computed by the procedure described
above, printed out to two decimal places and a total of six characters. By providing your phone number, you agree to receive a one-time
automated text message with a link to get the app. Standard
messaging rates may apply.
CLASS NAMES. Your program class should be called Babylonia
What I have so for:
import java.util.Scanner;
public class Babylonia My Textbook Solutions
{
public static void main(String[] args)
{
int n;
double guess;
Laboratory... Electronic... Signals and...
double r;
9th Edition 11th Edition 2nd Edition

https://www.chegg.com/homework-help/questions-and-answers/java-babylonian-algorithm-babylonian-algorithm-compute-square-root-positive-number-n-follo-q35119986#:~:text=Babylonian Algorithm.-,… 1/6


10/27/2020 Java Babylonian Algorithm. The Babylonian Algorith... | Chegg.com
Scanner input = new Scanner(System.in); View all solutions
 
NEW!
System.out.println("This Textbooksquare
program estimates Solutions
roots."); Expert Q&A Study Pack Practice  

System.out.print("Enter an integer to estimate the square root of: ");


n = input.nextInt(); Computer Science Chegg
System.out.println(); tutors who can help right
guess = n / 2.0; now
r = 0;
do Aditya A.
767
NIT Bhopal
{
if(guess != 0)
Bishrut J.
110
r = n / guess; BE Engineering
guess = (guess + r) / 2;
System.out.println("Current guess: " + guess); Rashi A.
213
G.B.pant university
}
while((r - guess > 0.01) || (guess - r > 0.01));
System.out.printf("The estimated square root of %d is %4.2f", n, guess);
Find me a tutor
}
}
Expected Output:
This program estimates square roots.
Enter an integer to estimate the square root of:
Current guess: 1.5
The estimated square root of 2 is 1.50

Actual Output:
This program estimates square roots.
Enter an integer to estimate the square root of:
Current guess: 1.5
Current guess: 1.4166666666666665
Current guess: 1.4142156862745097
The estimated square root of 2 is 1.41

Expert Answer

Friend answered this


Was this answer helpful? 1 0
9,648 answers

Here is the updated code, refer the screenshot for the output

https://www.chegg.com/homework-help/questions-and-answers/java-babylonian-algorithm-babylonian-algorithm-compute-square-root-positive-number-n-follo-q35119986#:~:text=Babylonian Algorithm.-,… 2/6


10/27/2020 Java Babylonian Algorithm. The Babylonian Algorith... | Chegg.com
--------------------------------------------------------------------------------------------------------------------------
 ----------------------- NEW!
Textbook Solutions Expert Q&A Study Pack Practice  

import java.util.Scanner;

public class Babylonia {


public static void main(String[] args) {
int n;
double guess;
double r;
Scanner input = new Scanner(System.in);
System.out.println("This program estimates square roots.");
System.out.print("Enter an integer to estimate the square root of: ");
n = input.nextInt();
System.out.println();
guess = n / 2.0;
r = 0;

double last_guess = guess;


do {
r = n / guess;
guess = (guess + r) / 2;
last_guess = guess;
System.out.println("Current guess: " + guess);
}
while (((guess - last_guess) / last_guess) > 0.01);
System.out.printf("The estimated square root of %d is %4.2f", n, guess);

--------------------------------------------------------------------------------------------------------------------------
-------------------------------

https://www.chegg.com/homework-help/questions-and-answers/java-babylonian-algorithm-babylonian-algorithm-compute-square-root-positive-number-n-follo-q35119986#:~:text=Babylonian Algorithm.-,… 3/6


10/27/2020 Java Babylonian Algorithm. The Babylonian Algorith... | Chegg.com

 
NEW!
Textbook Solutions Expert Q&A Study Pack Practice  

thank you !

Comment


Practice with similar questions

Q: The Babylonian algorithm to compute the square root of a positive number n 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 until the last two...

A: See answer
https://www.chegg.com/homework-help/questions-and-answers/java-babylonian-algorithm-babylonian-algorithm-compute-square-root-positive-number-n-follo-q35119986#:~:text=Babylonian Algorithm.-,… 4/6
10/27/2020 Java Babylonian Algorithm. The Babylonian Algorith... | Chegg.com

 
NEW!
Textbook Solutions Expert Q&A Study Pack Practice  

Up next for you in Computer Science

In cryptarithmetic Problem 2. The game of


puzzles, Pig
mathematical equations is a simple two-player
are dice
writtenusing letters.Each game in which the rst See more questions
letter can be a digit from player to reach 100 or for subjects you study
0 to more
9, but no two letters can points wins. Players take

See answer See answer

Questions viewed by other students

Q: Chapter 3 Exercise 1 Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive
number n 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 until the last two guess values are within 1% of each other.
Write a program that inputs an integer for...

A: See answer

Q: MYPROGRAMMINGLAB ASSIGNMENT. JAVA LANGUAGE

A: See answer

Show more 

COMPANY

https://www.chegg.com/homework-help/questions-and-answers/java-babylonian-algorithm-babylonian-algorithm-compute-square-root-positive-number-n-follo-q35119986#:~:text=Babylonian Algorithm.-,… 5/6


10/27/2020 Java Babylonian Algorithm. The Babylonian Algorith... | Chegg.com

LEGAL & POLICIES


 
NEW!
Textbook Solutions Expert Q&A Study Pack Practice  

CHEGG PRODUCTS AND SERVICES

CHEGG NETWORK

CUSTOMER SERVICE

© 2003-2020 Chegg Inc. All rights reserved.

https://www.chegg.com/homework-help/questions-and-answers/java-babylonian-algorithm-babylonian-algorithm-compute-square-root-positive-number-n-follo-q35119986#:~:text=Babylonian Algorithm.-,… 6/6

You might also like