import java.util.Scanner; //scanner class is needed for user input public class squareroot { { double n; //declares n, a variable that the user will give a value to n = input.nextDouble(); //assigns user input value to n root(n); //runs root method and passes the value of n to it } public static void root(double x) //root method accepts value passed to it as "x" { double y = Math.sqrt(x); //uses the Math.sqrt method in Java to calculate the square root and assigns it to y System.out.printf("The square root of " + x + " is approximately %.4f", y); //types out the result, and formats the square root to four decimal places } }