fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void teste(String s)
  13. {
  14. Pattern pattAlphaNum = Pattern.compile("[A-Z|a-z|\\d+]");
  15. Pattern pattAlpha = Pattern.compile("[A-Z|a-z]");
  16. Pattern pattNum = Pattern.compile("[\\d+]");
  17.  
  18. Matcher matchAlphaNum;
  19. Matcher matchAlpha;
  20. Matcher matchNum;
  21.  
  22. matchAlphaNum = pattAlphaNum.matcher(s);
  23. matchAlpha = pattAlpha.matcher(s);
  24. matchNum = pattNum.matcher(s);
  25.  
  26.  
  27. System.out.printf(matchAlphaNum.find()+"\t\t");
  28. System.out.printf(matchNum.find()+"\t\t");
  29. System.out.printf(matchAlpha.find()+"\t\t");
  30. System.out.println();
  31. }
  32.  
  33. public static void main (String[] args) throws java.lang.Exception
  34. {
  35. System.out.println("AlphaNum\tNum\t\t\tAlpha");
  36. teste("20");
  37. teste("a");
  38. teste("2a");
  39. teste("11");
  40. teste("1");
  41. }
  42. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
AlphaNum	Num			Alpha
true		true		false		
true		false		true		
true		true		true		
true		true		false		
true		true		false