Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class StringUtil {
- private StringUtil() { }
- /**
- * @param s
- * @return If the provided String only contains numerical characters
- */
- public static boolean isNumerical(String s) {
- for (int i = 0; i < s.length(); i++) {
- int val = s.charAt(i);
- if (val < '0' || val > '9') {
- return false;
- }
- }
- return true;
- }
- /**
- * @param s
- * @return If the provided String contains any numerical characters
- */
- public static boolean hasNumber(String s) {
- for (int i = 0; i < s.length(); i++) {
- int val = s.charAt(i);
- if (val >= '0' && val <= '9') {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment