1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
artcher [175]
3 years ago
12

The following method public String removeFromString(String old, String frag) removes all occurences of the string frag from the

string old. For example, removeFromString("hello there!", "he") returns "llo tre!" removeFromString("lalalala", "l") returns "aaaa" Which of the following blocks of code will successfully implement removeFromString()?
Computers and Technology
1 answer:
Mashutka [201]3 years ago
4 0

private static String removeFromString(String old, String frag)

{

int i = old.indexOf(frag);

while (i> -1) {

String rest = old.substring(i + frag.length());

System.out.println("rest = " + rest);

old = old.substring(0, i);

System.out.println("rest = " + old);

old = old + rest;

System.out.println("rest = " + old);

i = old.indexOf(frag);

System.out.println("i = "+ i);

}

return old;

}

Here the index of first occurrence is obtained outside the “while loop” and if this loop runs until index value is >-1. It extracts the rest of the characters other than “frag” from the index and all the characters for which the given set of characters are removed.

You might be interested in
What is a browser? Give one example
Harman [31]
It is a program that may be used by a user to access files and navigate the World Wide Web. An example of this would be Firefox, Chrome, Safari, etc.
3 0
3 years ago
Read 2 more answers
Which of the following is the correct order of laws (from local to state to federal)
professor190 [17]

Answer:

That, Federal law > Constitutional Law > State law > Local ordinances

Explanation:

4 0
3 years ago
Universal Containers (UC) has decided to build a new, highly sensitive application on the Force platform. The security team at U
Tresset [83]

Use an AppExchange product that does fingerprint scanning with native Salesforce Identity  Confirmation

8 0
3 years ago
Name three situations when a copy constructor executes.
Vesna [10]

Answer:

1. When an object of the class is passed (to a function) by value as an argument.

2.  When an object is constructed based on another object of the same class.

3. When compiler generates a temporary object.

Explanation:

7 0
2 years ago
Maxwell says three things Level Two Leaders do well are:
IRINA_888 [86]

Answer:

true

Explanation:

3 0
3 years ago
Other questions:
  • ou work as network administrator for an organization that has a Windows-based network. You want to use multiple security counter
    10·1 answer
  • You use different office apps to accomplish specific tasks, such a creating a newsletter or producing a sales presentation, yet
    8·1 answer
  • Discuss some design considerations that you should keep in mind when you want to design a professional-looking flyer or newslett
    12·1 answer
  • Please list ten things that you have learned an Excel Spreadsheet can do.
    7·1 answer
  • Blender is used by which video game team member?
    15·1 answer
  • Why do chloroplasts appear only in plant cells and lysosomes appear only in animal cells?
    13·1 answer
  • The create_python_script function creates a new python script in the current working directory, adds the line of comments to it
    6·1 answer
  • ALSO PLZZZ HELP :P Suppose you are purchasing a game at a local retail store that comes on DVD. In order to install it on your l
    8·1 answer
  • The New option is found in the ...............tab.​
    6·2 answers
  • A group of two or more computer systems linked together via communication devices is called:.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!