1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svetlana [45]
3 years ago
15

Let’s say you are given a number, a, and you want to find its square root. One way to do that is to start with a very rough gues

s about the answer, x0, and then improve the guess using the following formula: x1 = (x0 + a/x0)/2 For example, if we want to find the square root of 9, and we start with x0 = 6, then x1 = (6 + 9/6)/2 = 15/4 = 3.75, which is closer. We can repeat the procedure, using x1 to calculate x2, and so on. In this case, x2 = 3.075 and x3 = 3.00091. So that is converging very quickly on the right answer(which is 3). Write a method called squareRoot that takes a double as a parameter and that returns an approximation of the square root of the parameter, using this technique. You may not use Math.sqrt. In java
Computers and Technology
1 answer:
o-na [289]3 years ago
7 0

Answer:

Check the explanation

Explanation:

package com.squarerrot;

public class SquareRoot {

/**

*

*/

public static double squareRoot(double input) {

System.out.println("Trace for input:" + input);

//random value initialized to 6 here

double output, guessValue = 6, previousValue = 0;

while (input - (output = approximateValue(input, guessValue)) >= 0.00005

&& previousValue != output) {

guessValue = output;

previousValue = output;

System.out.println(output);

}

return output;

}// end of method squareRoot

// calculate the approximate value

public static double approximateValue(double input, double start) {

return (start + (input / start)) / 2;

}// end of method approximateValue

// test the square root method

public static void main(String[] args) {

System.out.println("Square Root of 9:" + squareRoot(9));

System.out.println("Square Root of 16:" + squareRoot(16));

}// end of method main

}// end of the class

You might be interested in
Write a C program to perform simple C arithmetic calculations. The user is to enter a simple expression (integer operator intege
Ilya [14]

Answer:

Input example:

select the funcion: 1                                                                                                                  

write the 1sd number2                                                                                                                  

write the 2nd number1                                                                                                                  

value is 2.000000                                                                                                                      

Explanation:

#include <stdio.h>

main()

{

//define the variables as float

float a, b, c, e;

char d;

while (1)  

{      

//input values

printf("select the function: ");

scanf("%c",&d);

printf("write the 1sd number");

scanf("%f",&a);

getchar();

printf("write the 2nd number");

scanf("%f",&b);

getchar();

if (d=='%')

{

    a=a*b/100;

}

if (d=='*')

{

    a=a*b;

}

if (d=='+')

{

    a=a+b;

}

if (d=='/')

{

    a=a/b;

}

if (d=='-')

{

    a=a-b;

}

printf("value is %f \n",a);

}

printf("final value is %f",a);

getchar();

}

8 0
4 years ago
An email message containing a warning related to a non-existent computer security threat, asking a user to delete system files f
LenKa [72]

Answer: Virus Hoax

Explanation:

A computer virus hoax is a message that warns someone of a false virus threat. It is a a chain email that encourages who ever has received the message to pass it to other people as a form of warning.

5 0
3 years ago
Which of the following is a great collection of resources for those entering the workplace or embarking on a new career?
Sloan [31]
Please type in the following.
Thanks
6 0
3 years ago
Read 2 more answers
What is a relationship between a object and a class?
bonufazy [111]

Hiya!


Of the options given, I would say A. An object is an instance of a class is the correct choice.

Hope this helps!

6 0
3 years ago
Read 2 more answers
Has the worst state of seat belt usage in the nation
german
Hope this helps pls thank me

7 0
4 years ago
Other questions:
  • Write a program whose inputs are three integers, and whose output is the smallest of the three values.
    6·1 answer
  • Employees of Bodegas &amp; Bistros Inc. (2B) maintain a password-protected social media page to "vent about work." When 2B learn
    12·1 answer
  • Is downloading like installing?
    13·1 answer
  • Which cell address indicates the intersection of the first row and the first column in worksheet?
    12·2 answers
  • Assume the availability of an existing class, ICalculator, that models an integer arithmetic calculator and contains:an instance
    12·1 answer
  • This document shows a student's education and career goals and a way to achieve those goals.
    8·1 answer
  • A developer is creating an enhancement to an application that will allow people to be related to their employer. Which data mode
    11·1 answer
  • How have the computers contributed in the banking ?<br>​
    6·1 answer
  • assuming the default gateway is connected to the internet, what type of internet access would this server have?
    14·1 answer
  • What is the purpose of system software?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!