Here's the problem " (Math: approximate the square root) There are several techniques for implementing the sqrt method in the Math class. One such technique is known as the Babylonian method. It approximates the square root of a number, n, by repeatedly performing a calculation using the following formula: nextGuess = (lastGuess + n / lastGuess) / 2 When nextGuess and lastGuess are almost identical, nextGuess is the approximated square root. The initial guess can be any positive value (e.g., 1). This value will be the starting value for lastGuess. If the difference between nextGuess and lastGuess is less than a very small number, such as 0.0001, you can claim that nextGuess is the approximated square root of n. If not, next- Guess becomes lastGuess and the approximation process continues. Implement the following method that returns the square root of n. public static double sqrt(long n)" I have my java code here " import java.util.Scanner; public class Main2 { public static void main(String[] args) { // Create Scanner input; scanner out = new Scanner(System.in); // Variables are declared in the constructor double sqrt(long n) double nextGuess; double lastGuess; // Have user input a number system.out.printf("Write a number"); long n = input.nextLong(); // Determine the square root of the number system.out.printf("The square root of %i is %.4d\n "); } public static double sqrt(long n) { // Provide known variables double errorThreshold = 0.0001; double difference = 0.01; double nextGuess = n / 2; double lastGuess = n; // Provide the loop threshold is at least the difference while (difference >= errorThreshold); { nextGuess = (lastGuess + (n / lastGuess)) / 2; // A new difference is calculated difference = math.abs(nextGuess * nextGuess - n) >= 0.0001; // Provide the conclusion lastGuess = nextGuess; } } }" These are the errors "7:20 java: ';' expected, 7:27 java: ';' expected" How do I fix it so that I can run?
Here's the problem "
(Math: approximate the square root) There are several techniques for implementing
the sqrt method in the Math class. One such technique is known as the
Babylonian method. It approximates the square root of a number, n, by repeatedly
performing a calculation using the following formula:
nextGuess = (lastGuess + n / lastGuess) / 2
When nextGuess and lastGuess are almost identical, nextGuess is the
approximated square root. The initial guess can be any positive value (e.g., 1).
This value will be the starting value for lastGuess. If the difference between
nextGuess and lastGuess is less than a very small number, such as 0.0001,
you can claim that nextGuess is the approximated square root of n. If not, next-
Guess becomes lastGuess and the approximation process continues. Implement
the following method that returns the square root of n.
public static double sqrt(long n)"
I have my java code here "
public class Main2 {
public static void main(String[] args) {
// Create Scanner input;
scanner out = new Scanner(System.in);
// Variables are declared in the constructor
double sqrt(long n)
double nextGuess;
double lastGuess;
// Have user input a number
system.out.printf("Write a number");
long n = input.nextLong();
// Determine the square root of the number
system.out.printf("The square root of %i is %.4d\n ");
}
public static double sqrt(long n) {
// Provide known variables
double errorThreshold = 0.0001;
double difference = 0.01;
double nextGuess = n / 2;
double lastGuess = n;
// Provide the loop threshold is at least the difference
while (difference >= errorThreshold);
{
nextGuess = (lastGuess + (n / lastGuess)) / 2;
// A new difference is calculated
difference = math.abs(nextGuess * nextGuess - n) >= 0.0001;
// Provide the conclusion
lastGuess = nextGuess;
}
}
}"
These are the errors "7:20
java: ';' expected,
7:27
java: ';' expected"
How do I fix it so that I can run?
Step by step
Solved in 3 steps with 1 images