Question
need a java structure chart for my below java program import java.util.Scanner; public class Problem_6_22 { public static void main(String[] args) { boolean run =
need a java structure chart for my below java program
import java.util.Scanner;
public class Problem_6_22 { public static void main(String[] args) { boolean run = true; while(run) { //Creates a Scanner to take in user input Scanner input = new Scanner(System.in);
//Prompts the user to enter an integer System.out.printf("Enter a number: "); long number = input.nextLong();
//Displays the square root System.out.printf("The approximated square root of " + number + " is: " + sqrt(number)); System.out.printf(" "); } }
public static double sqrt(long n) { //makes the initial guess to positive value long lastGuess = 1; long nextGuess = (lastGuess + n / lastGuess) / 2;
//If the difference between nextGuess and lastGuess is less than 0.0001, //it returns nextGuess as the approximated square root of n. while (nextGuess - lastGuess > 0.0001) { lastGuess = nextGuess; nextGuess = (lastGuess + n / lastGuess) / 2; } lastGuess = nextGuess; return nextGuess = (lastGuess + n / lastGuess) / 2; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started