run this code and let me know if there are any syntax errors thank you. import java.util.Scanner;
Question:
run this code and let me know if there are any syntax errors thank you.
import java.util.Scanner; // Import Scanner import java.lang.Math; // Import Math
public class Part095SqrtAssignment { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Create a new Scanner System.out.print("Enter a number: "); double x = scanner.nextDouble(); // Read the number from the user
double estimate = 2; double error = 0.0001; double difference = Math.abs(estimate * estimate - x); // Write a while loop to update the estimate and difference while (difference > error) { estimate = (estimate + x / estimate) / 2.0; difference = Math.abs(estimate * estimate - x); }
// Print the estimate and the true square root System.out.println("Estimated square root: " + estimate); System.out.println("True square root: " + Math.sqrt(x)); scanner.close(); // Close the scanner } }
Essentials Of Business Communication
ISBN: 9781337386494
11th Edition
Authors: Mary Ellen Guffey, Dana Loewy