fork download
  1. import java.util.regex.Pattern;
  2.  
  3. /* package whatever; // don't place package name! */
  4.  
  5. /* The class name doesn't have to be Main, as long as the class is not public. */
  6. class Main {
  7. public static void main(String[] args) throws java.lang.Exception {
  8. for(int i = 0; i < 500000; i++){
  9. isAlpha("abc123def456hig789klm000");
  10. isAlpha("abcdefghijklmnopqrstuvwxyz");}
  11.  
  12. // for(int i = 0; i < 5000000; i++){
  13. // isOnlyWordChars("abc123def456hig789klm000");
  14. // isOnlyWordChars("abcdefghijklmnopqrstuvwxyz");}
  15.  
  16. // for(int i = 0; i < 5000000; i++){
  17. // isAlpha("abc123def456hig789klm000");
  18. // isAlpha("abcdefghijklmnopqrstuvwxyz");}
  19. }
  20.  
  21. private static boolean isOnlyWordChars(String s) {
  22. char[] chars = s.toCharArray();
  23. for (char c : chars) {
  24. if (!Character.isLetter(c)) {
  25. return false;
  26. }
  27. }
  28. return true;
  29. }
  30.  
  31. private static boolean isAlpha(String str) {
  32. if (str == null) {
  33. return false;
  34. }
  35. int sz = str.length();
  36. for (int i = 0; i < sz; i++) {
  37. if (Character.isLetter(str.charAt(i)) == false) {
  38. return false;
  39. }
  40. }
  41. return true;
  42. }
  43.  
  44. private static final Pattern sOnlyWordChars = Pattern.compile("\\w+");
  45.  
  46. private static boolean isOnlyWordChars2(String s) {
  47. return sOnlyWordChars.matcher(s).matches();
  48. }
  49.  
  50. }
Success #stdin #stdout 0.33s 380160KB
stdin
1
2
`42
11
stdout
Standard output is empty