Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

counting repeated characters in a string in java

String s="mmababctamantlslwgikl";
    int distinct = 0 ;

    while(s.length()>0){
        
        for (int j = 0; j < s.length(); j++) {

            if(s.charAt(0)==s.charAt(j))
            {
                distinct++;

            }
        }   
        
        System.out.println(s.charAt(0)+"--"+distinct);
        String d=String.valueOf(s.charAt(0)).trim();
        s=s.replaceAll(d,"");
        distinct = 0;

        
    }
 
PREVIOUS NEXT
Tagged: #counting #repeated #characters #string #java
ADD COMMENT
Topic
Name
2+1 =