Alternating Characters

  • + 0 comments
    public static int alternatingCharacters(String s) {
        // Write your code here
        int count = 0 ;
        for (int i = 1 ; i < s.length(); i++){
            if(s.charAt(i) == s.charAt(i-1)){
                count +=1;
            }
        }
        return count;
    
        }