0
Please, How I check if the string digits “number” or not ? “Java”
I have a string variable enters from console because I need check the length but in the same time I want check if it digit or not
3 ответов
+ 1
You need to make a Boolean function which return true if string you entered can parse to any other numeric data type. Like this:
public static Boolean checkstr(String str)
try{
Double.parseDouble(str);
return True;
}
catch(Exception e)
{
Return False
}
Do this after you find the length of string.
Because this function will convert your string to number and then you can't use
.length() method on your string.
:)
0
myObject.getClass().getName(); // Its show type of your object.
0
Did you mean you want to check each character in the string for being a digit (0-9)?
Why you tagged 'iostream'? isn't that C++ header file?