fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. int digit = 0, letter = 0, punc = 0;
  15. char c;
  16. String sentence = "abc, (kl{}";
  17.  
  18. for (int a = 0; a<sentence.length(); a++){
  19. c=sentence.charAt(a);
  20.  
  21.  
  22. if(Character.isLetter(c))
  23. letter++;
  24.  
  25. if(Character.isDigit(c))
  26. digit++;
  27.  
  28. if(("" + c).matches("[\\p{Punct}]")){
  29. punc++;
  30. }
  31.  
  32. }
  33. System.out.println(punc);
  34. }
  35. }
Success #stdin #stdout 0.12s 321600KB
stdin
Standard input is empty
stdout
4