
Write a complete program in a single class called RootMaker, which reads in an integer value from the keyboard, and places it in a variable, say num. If num is non-negative, the program should print the square root of num. However, if num is negative, the program should then print the phrase "negative input".

Java find square root of a number:
import java.util.*;
class RootMaker
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Number: ");
int num=input.nextInt();
if(num>0){
double root=Math.sqrt(num);
System.out.println("Square root of "+num+" is: "+root);
}
else{
System.out.println("Negative Input!");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.