哎呀 我也做了这一题,也是通过不了
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);  while (sc.hasNext()) {
        String str = sc.nextLine();  int count = 0;  char c,c1;  for (int i = 0; i <str.length() ; i++) {
            c = str.charAt(i);  if(i!=str.length()-1){
                c1 = str.charAt(i+1);  }else {
                c1 = c;  } if(c!=c1){
                count++;  }

        }
        System.out.println(count);   }
}