Question:
Given an input string, check if it is in a valid number format.
Analysis:
Valid number format can be either positive or negative, can be integer or float number.
Solution 1:
Directly call Java library method and if the string is not in a valid format, it will throw out an exception. Return false if catching an exception.
Solution 2:
Make a regular expression and call the string library method to see if the input matches the pattern.
Solution 3:
Start from no library method available. Compare and make decision based on the characters in the input.
No comments:
Post a Comment