我写了一个文本,我想将一些字符更改为用户将选择它们的任何其他字符,我尝试并找不到正确的答案,所以请指导我。MyTest 类中的代码是:
public String replace(String input,char from,char to){
String input2 ="";
String input3="";
this.input=input3;
for(int i=0;i<input.length();i++){
for(int j=0;j<input3.length();j++){
if(input.charAt(i)==input3.charAt(j)){
input2=input3.replace(from, to);
System.out.println(input2);
}
}
}
return input2;
}
主类中的代码:
System.out.println("please enter the new character: ");
char c1 = scan.next().charAt(0);
System.out.println("Please choose the letters that you want to change it which in the text:");
String ltr = scan.next();
obj1.convertChars(ltr, c1);