- 1
How to check whether the entered input is string or integer or float in java ?
2 Respostas
+ 2
you can use this code
int no=0;
try
{
no=Integer.parseInt(string);
if(string.contains("."))
{
if(string.contains("f"))
{
System.out.println("float");
}
else
System.out.println("double");
}
}
catch(Exception ex)
{
Console.WriteLine("not numeric or string");
}
+ 2
You can check if the entered text is a number using regular exceptions.
Or you simply try to convert it to number and it is a number of conversion was OK:
try {
int number = Integer.parseInt(input);
// number
} catch (NumberFormatException e) {
// not a number
}