Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

counting repeated characters in a string in java

 void Findrepeter(){
    String s="mmababctamantlslmag";
    int distinct = 0 ;

    for (int i = 0; i < s.length(); i++) {

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

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

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

    }

}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #counting #repeated #characters #string #java
ADD COMMENT
Topic
Name
5+6 =