Answer:
Program in Java:
import java.lang.Math;
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
double num;
System.out.print("Enter any number: ");
num = input.nextDouble();
num = Math.abs(num);
System.out.print("Square root: "+Math.sqrt(num));
}
}
Step-by-step explanation:
This line imports the math library
import java.lang.Math;
This line imports the scanner library
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
This line declares num as double
double num;
This line prompts user for input of number
System.out.print("Enter any number: ");
This line gets the input from the user
num = input.nextDouble();
This line calculates the absolute value of the number input by the user
num = Math.abs(num);
This line calculates and prints the square root of the number inputted
System.out.print("Square root: "+Math.sqrt(num));
}
}