char tmpCh
int[] num = {0,0,0,0};
for(int i = 0; i< s.length(); i++)
{
tmpCh = s.charAt(i);
if(tmpCh > '0' && tmpCh < '9')
{
num[0]++;
}
else if(tmpCh > 'A' && tmpCh < 'Z')
{
num[1]++;
}
else if(tmpCh > 'a' && tmpCh < 'z')
{
num[2]++;
}
else
num[3]++;
}

解决方案 »

  1.   

    //刚才不太对,空格 ASCII 码是32
    char tmpCh
    int[] num = {0,0,0,0};
    for(int i = 0; i< s.length(); i++)
    {
    tmpCh = s.charAt(i);
    if(tmpCh > '0' && tmpCh < '9')
    {
    num[0]++;
    }
    else if(tmpCh > 'A' && tmpCh < 'Z')
    {
    num[1]++;
    }
    else if(tmpCh > 'a' && tmpCh < 'z')
    {
    num[2]++;
    }
    else if(tmpCh == 32)
    num[3]++;
    }
      

  2.   

    如果仅仅是要得出它们的个数的话,应用DainelLee的程序就可以了;但要将其余的字符串分别放在一个数组里,我建议还是使用正则表达式比较好