95.7k views
2 votes
Or Java,

program to perform this computa
3.
Isaac Newton devised a clever method to casily approximate the square root of a number without having
to use a calculator that has the square root function. Describe this method with illustration​

1 Answer

5 votes

Answer:

The illustration in Java is as follows:

import java.util.*;

import java.lang.Math.*;

class Main{

public static void main (String[] args){

Scanner input = new Scanner(System.in);

double num, root, temp;

num = input.nextDouble();

temp = num;

while (true){

root = 0.5 * ( (num / temp)+temp);

if (Math.abs(root - temp) < 0.00001){

break; }

temp = root; }

System.out.println("Root: "+root);

}}

Step-by-step explanation:

This declares all necessary variables

double num, root, temp;

This gets input for num (i.e the number whose square root is to be calculated)

num = input.nextDouble();

This saves the input number to temp

temp = num;

This loop is repeated until it is exited from within the loop

while (true){

Calculate temporary square root

root = 0.5 * ( (num / temp)+temp);

The loop is exited, if the absolute difference between the root and temp is less than 0.00001

if (Math.abs(root - temp) < 0.00001){

break; }

Save the calculated root to temp

temp = root; }

This prints the calculated root

System.out.println("Root: "+root);

User DJphilomath
by
3.1k points