public class ReplaceVowels {
public static void main(String args[]) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String:");
String str = bf.readLine();
char[] c = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
if (c[i] == 'a' || c[i] == 'e' || c[i] == 'i' || c[i] == 'o'
|| c[i] == 'u') {
System.out.println(str.replace(c[i], '?'));
}
}
}
}
为什么 str.replace
方法不起作用?我应该怎么做才能让它起作用?
str.replace
不会修改原始字符串,它将返回一个具有修改内容的新/单独字符串。你可能想要使用str = str.replace(...)
。 - Pshemo