怎样判断字符串中有几个数字和标点符号

解决方案 »

  1.   

    String包好像有个stoken(不记得怎么拼了,大致如此)方法可以分离和统计特殊符号
      

  2.   

    //输入字符串中字符中字母,数字和其他字符数目。class  e2{
      public static void main(String args[])
        throws java.io.IOException{
        int count_char=0;
        int count_number=0;
        int count_other=0;
        String s=" ";
        char   c=' ';
        System.out.print("Please input the String numbers:");
        
        c=(char) System.in.read();  //就是这行,怎么输入字符串??      for(int i=0;i<s.length();i++){   //从字符串中逐个获取字符
            
            if(c>='a'&&c<='z'||c>='A'&&c<='Z')  count_char++;    //统计字母个数
            
            else if(c>='0'&&c<='9')  count_number++;             //统计数字个数
            
                 else   count_other++;
         }
         System.out.println("count_char="+count_char);
         System.out.println("count_number"+count_number);
         System.out.println("count_other"+count_other);
      }
    }