提问:字符串“my address is #168 shanghai Road,beijing,100028",要求编写程序统计改字符串中字母、数字、空格和其他字符的个数?请赐教

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【bll19840729】截止到2008-07-10 09:44:48的历史汇总数据(不包括此帖):
    发帖的总数量:0                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:---------------------结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    public class Test
    {
    public static void main(String[] args) 
    {
    String s="my address is #168 shanghai Road,beijing,100028";
    int countNum=0;
    int countStr=0;
    int countSpace=0;
    int countOther=0;
    for(int i=0;i<s.length();i++){
    char c=s.charAt(i);
    if(('0'<=c)&&(c<='9'))
    countNum++;
    else if(c==' ')
    countSpace++;
    else if((('A'<=c)&&(c<='Z'))||(('a'<=c)&&(c<='z')))
    countStr++;
    else
    countOther++;
    }
    System.out.println(countNum+","+countStr+","+countSpace+","+countOther);
    }
    }
      

  3.   


    public class Test
    {
        public static void main(String[] args) 
        {
            String s="my address is #168 shanghai Road,beijing,100028";
            int countNum=0;
            int countStr=0;
            int countSpace=0;
            int countOther=0;
            for(int i=0;i<s.length();i++){
                char c=s.charAt(i);
                if(('0'<=c)&&(c<='9'))
                    countNum++;
                else if(c==' ')
                    countSpace++;
                else if((('A'<=c)&&(c<='Z'))||(('a'<=c)&&(c<='z')))
                    countStr++;
                else
                    countOther++;
            }
            System.out.println(countNum+","+countStr+","+countSpace+","+countOther);
        }
    }
      

  4.   

    -------------------------------------------------------------
                Quietly through  .....