String str = "asdfasdfasdfasdf"; char c = 'a'; str = str.replaceAll(str,c+""); /* 输入用Scanner input = new Scanner(System.in); input.next()来实现,具体调用哪个函数我忘记了,你自己运行看吧。 还有,replaceAll(str,c+"");不行的话,就用replaceAll(c+"",str); */
清雅幽兰
2024-06-06 03:52:23
import java.util.*; public class App5_9 { public static void main(String []args) { System.out.print("请输入一个字符串:"); String str = new Scanner(System.in).nextLine(); System.out.print("请输入要删除的字符:"); String str1 = new Scanner(System.in).nextLine(); System.out.println(str.replaceAll(str1,""));
} }
不觉素颜
2024-06-06 05:33:06
#include <iostream> #include <string.h>
using namespace std;
int main() { char str[100],ans[100],ch; while(scanf("%s %c",str,&ch)!=EOF) { int i,len=strlen(str);
for(i=0;i<len;i++) if(str[i]==ch) str[i]=-1;
int index=0; for(i=0;i<=len;i++) if(str[i]!=-1) ans[index++]=str[i];