Answer the question
In order to leave comments, you need to log in
Why doesn't the program work without the second 'return'?
Good day.
There is a task within the framework of which it is required to remove all substrings (remove) from one string (base), case insensitive. The problem was solved in the following way:
public String withoutString(String base, String remove) {
String result = "";
for (int i = 0; i < (base.length()-remove.length()+1); i++)
if (!base.substring(i, i+remove.length()).toLowerCase().equals(remove.toLowerCase()))
result += base.substring(i, i+1);
else if (i+remove.length() < base.length())
i += remove.length()-1;
else
return result;
for (int j = base.length()-remove.length()+1; j < base.length(); j++)
result += base.substring(j, j+1);
return result;
}
else
return result;
Answer the question
In order to leave comments, you need to log in
I would advise you to redo the solution of the problem, and not look for an error in this code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question