java学习之string编程题

统计某个字符在目标字符串中出现的次数
public class test{
    public static void main(String[] args){
    String str="李荣lir999ong4567899";
    String c="9";
    int j=0;
//    char[] arr=str.toCharArray();
        for(int i=0;i
        String b =str.charAt(i)+"";
        
            if(b.equals(c)){
            
                j=j+1;
            }
        }
    System.out.println(j);    
    }
}
实现字符串逆序    字符串的旋转
public class test{

    public static void main(String[] args){
    
    String ss="abcdefg";
    StringBuffer sb=new StringBuffer();
        for(int i=ss.length()-1;i>=0;i--){    
        sb.append(ss.charAt(i));        
        }    
    System.out.println(sb.toString());    
    }
}

3   去掉字符串中的特殊字符
public class test{

    public static void main(String[] args){
    String str="123.456.78.56";
    String[] arr= str.split("\\.");
    
    StringBuffer sb=new StringBuffer();
        for(int i=0;i
        
            sb.append(arr[i]);
        }
        System.out.println(sb.toString());
    
    }}
    
去除字符串中的重复字符
public class test{

    public static void main(String[] args){
    String str="123.456.78.56";
    String[] arr= str.split("\\.);
    
    StringBuffer sb=new StringBuffer();
        for(int i=0;i
        
            sb.append(arr[i]);
        }
        System.out.println(sb.toString());
    
    }}
统计字符串中每个字符出现的次数
public class test{

    public static void main(String[] args){
    String str="ssd1dfffgggg";
        int len=str.length();
        HashMap map=new HashMap();
            for(int i=0;i
            
            String cc=str.charAt(i)+"";
            Integer inte=map.get(cc);
                if (inte==null){
                map.put(cc,1);
                }
                else{
                map.put(cc,inte.intValue()+1);
                }                
            }                
        System.out.println(map);        
    }}



你可能感兴趣的:(java学习之string编程题)