有没有办法通过创建一个等于该字符的新字符串变量来解决这个问题import java.util.Scanner;public class mean_and_scary {    public static void main(String args[]) {        Scanner scanner = new Scanner(System.in);        System.out.println("Enter Text:");        String text = scanner.nextLine();        char leftchar = scanner.next().charAt(0);        char rightchar = scanner.next().charAt(0);        char removechar = scanner.next().charAt(0);        int width = scanner.nextInt();        text = text.replace(removechar, ""); // at this point        text = text.toUpperCase();        System.out.println(text);        scanner.close();    }}
                    
                    
                3 回答
 
                    
                    
                            繁星淼淼
                            
                                
                            
                        
                        
                                                
                    TA贡献1775条经验 获得超11个赞
错误是String类中没有带有参数(char,String)的方法
试试这个: text = text.replace(removechar + "", "");
 
                    
                    
                            紫衣仙女
                            
                                
                            
                        
                        
                                                
                    TA贡献1839条经验 获得超15个赞
错误发生,因为该方法.replace(char,String)的String类不存在,这样他们就可以找到它。
public static void main(String[] args) {
"Test".replace("",""); // OK because the method replace with params CharSequence,CharSequence exist
"Test".replace('e', '\u0000'); // OK because the method replace with params char,char exist
"Test".replace('\u0000', ""); // Not OK because the method don't exist
}
 
                    
                    
                            小怪兽爱吃肉
                            
                                
                            
                        
                        
                                                
                    TA贡献1852条经验 获得超1个赞
您可以用以下内容替换该行:
text = text.replace(String.valueOf(removechar), ""); // at this point
添加回答
举报
0/150
	提交
		取消
	