用StringBuffer替换特定位置字符

 

import java.util.*;
public class Solution {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

while(sc.hasNextLine()){
StringBuffer s=new StringBuffer();
s.append(sc.nextLine());
if(s.length()>=1&&s.length()<=10)
{
int j=0;
for(int i=0;i<s.length()-1;i++){
if(s.charAt(i)==s.charAt(i+1)){
j++;
s.setCharAt(i+1,'Z');//替换特定字符
}
}

System.out.println(j);
}
else continue;
}
}
}

posted @ 2017-07-25 20:02  code666  阅读(5028)  评论(0编辑  收藏  举报