编写Java程序,在每个旁边放置的任何重复字母之间插入“#” . 例如,给定以下字符串“Hello world”,输出应为“Hel#lo world”
String str = "Hello java world";
char a = '#';
for (int i=0; i<str.length(); i++ ) {
if (str.charAt(i) == str.charAt(i+1)){
String temp = str + a;
System.out.println(temp);
}
}
1 回答
好吧,你可以尝试:
Example 1: Using REGEX
Example 2: Using string manipulations
还有更多......