测试一字符串在另一字符串中出现的次数,Character的运用

 

public   static   void  test1() {
        String s
="AaaaABBBBcc&^%adfsfdCCOOkk99876 _haHA";
        
int lCount=0,uCount=0,oCount=0,nCount=0;
        
for(int i=0;i<s.length();i++)
        
{
            
char c=s.charAt(i);
//            if(c>='a'&&c<='z')
//            {
//                lCount++;
//            }else if(c>='A'&&c<='Z')
//            {
//                uCount++;
//            }
//            else
//            {
//                oCount++;
//            }
            if(Character.isLowerCase(c))
            
{
                lCount
++;
            }
else if(Character.isUpperCase(c))
            
{
                uCount
++;
            }

            
else if(Character.isDigit(c))
            
{
                nCount
++;
            }
else
            
{
                oCount
++;
            }

                 
        }

        System.out.println(lCount
+"  "+uCount+"  "+nCount+"  "+oCount);
    }

    
public   static   void  test2() {
        
int count=0,index=-1;
        String s 
= "sunjavahpjavaokjavajjavahahajavajavagoodjava";
        String sFind
="java";
        
while((index=s.indexOf(sFind))!=-1)
        
{
            s
=s.substring(index+sFind.length());
            count
++;
        }

        System.out.println(count);

    }

你可能感兴趣的:(C++,c,C#)