在尝试创建所有 java 函数时,我编写了自己的 deleteSubString 方法。但是我对它产生的输出有疑问。这是我的代码:
//deleteSubString
String subString = "ON";
String delString = "PONY";
String emp = "";
int delIndex = 0;
for(int i=0; i<delString.length()-1; i++){
if(delString.contains(subString)){
//do nothing
//read the rest of the string to confirm it contains
for(int j=delIndex; j<delString.length()-1; j++){
if(delString.contains(subString)){
//do nothing
}
else{
emp += delString.charAt(j);
}
}
}
System.out.println("Delete SubString");
System.out.println(emp);
}
我期望发生的是将字符串打印为“PY”,但它选择根本不打印任何内容。任何想法将不胜感激!