Hi, I need to write a simple program to input a number and display the square root of it. I need to use methods but my code does not work properly. I am also a bit confused with methods and passing parameters so could someone please explain it to me.
Here is my code:
Here is my code:
import java.util.*;
public class SqrtMethod {
static Scanner kb = new Scanner(System.in);
public static int input()
{
System.out.println("Enter a number");
int num = kb.nextInt();
return num;
}
public static double FindSqrt(int num)
{
double sqrt = Math.sqrt(num);
return sqrt;
}
public static void Output(double sqrt)
{
System.out.println("The square root is: " + sqrt);
}
public static void main(String[]args)
{
input();
int num=0;
double sqrt = FindSqrt(num);
Output(sqrt);
}
}