My problem is that I am asking for a number by keyboard to get the square root, but if it is less than 0 the code should not be executed, I do it but it throws me this problem:
Problem
Ingrese el radicando
-9
La raíz de -9.0 es: NaN
Code
import java.util.Scanner;
public class RaizCuadrada {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num;
float resultado;
System.out.println("Ingrese el radicando");
num = sc.nextInt();
if(num <= 0) {
System.out.println("Debe ingresar un numero mayor a 0");
}else{
resultado = (float) Math.sqrt(num);
System.out.println("La raiz de " + num + " es: " + resultado);
}
}
}