COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
Decides if a string only contains numbers
|
isalpha()
|
|
isnumeric()
|
|
int()
|
|
string()
|
Explanation:
Detailed explanation-1: -The isnumeric() method returns True if all the characters are numeric (0-9), otherwise False. Exponents, like ² and ¾ are also considered to be numeric values. “-1” and “1.5” are NOT considered numeric values, because all the characters in the string must be numeric, and the-and the .
Detailed explanation-2: -parseInt() or Double. parseDouble(). That’ll tell you right away if a String is only numbers (or is a number, as appropriate).
Detailed explanation-3: -You can use the isdigit() macro to check if a character is a number. Using this, you can easily write a function that checks a string for containing numbers only. Subminiature stylistic sidenote: returns true for the empty string.
There is 1 question to complete.