需要判断给定的
public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); System.out.println("请输入:"); String value = scanner.next(); System.out.println("请输入需要删除的字符:"); String value1 = scanner.next(); int judge = value1.indexOf(value1); //字符串是否存在,找到并删除 if(judge != -1){ System.out.println(value.replace(value1,"")); }else { System.out.println("没有找到需要删除的字符串"); } } }