astrit

Untitled

Feb 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public final class StringUtil {
  2.  
  3. private StringUtil() { }
  4.  
  5. /**
  6. * @param s
  7. * @return If the provided String only contains numerical characters
  8. */
  9. public static boolean isNumerical(String s) {
  10. for (int i = 0; i < s.length(); i++) {
  11. int val = s.charAt(i);
  12. if (val < '0' || val > '9') {
  13. return false;
  14. }
  15. }
  16.  
  17. return true;
  18. }
  19.  
  20. /**
  21. * @param s
  22. * @return If the provided String contains any numerical characters
  23. */
  24. public static boolean hasNumber(String s) {
  25. for (int i = 0; i < s.length(); i++) {
  26. int val = s.charAt(i);
  27. if (val >= '0' && val <= '9') {
  28. return true;
  29. }
  30. }
  31.  
  32. return false;
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment