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]
2 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]2 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
You are a psychologist who needs to provide a qualitative evaluation for IQ scores. Create a program that takes IQ scores (one a
dsp73

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <iomanip>

using namespace std;

int getIQ(); // return the score

void printEvaluation(int);

int main()

{

   int IQ = 0;

   IQ = getIQ();

   

   printEvaluation(IQ);

   return 0;

}

int getIQ()

{

   int score = 0;

   cout << "Please enter your IQ Score to receive your IQ Rating:\n";

   cin >> score;

   

   return score;

}

void printEvaluation(int aScore)

{

   cout << "IQ Score: " << aScore << " IQ Rating: ";

   

   if (aScore <= 100)

   {

       cout << "Below Average\n";

   }

   else if (aScore <= 119)

   {

       cout <<"Average\n";

   }

   else if (aScore <= 160)

   {

       cout << "Superior\n";

   }

   else if (aScore >= 160 )

   {

       cout << "Genius\n";

   }

}

4 0
3 years ago
Name two different ways you can bring up the my computer folder
sweet [91]

The My Computer folder is a multipurpose tool and is a gateway to all the data stored in the computer. This folder sits at the top of your laptop or PC. It can be found on your computer’s desktop, on the start menu and within the windows explorer. <u>Clicking or double clicking on these options will bring up the My Computer folder. </u>

<u>Another easier way of doing this is to hold down the windows + E combination keyboard keys.</u>

7 0
3 years ago
Read 2 more answers
On laptops with a smart card reader installed, where is the smart card reader usually located?
dem82 [27]
Plenty of space in the palm rest
4 0
3 years ago
One of the main responsibilities employers have under OSHA is to:
poizon [28]
What dose osha means please
7 0
3 years ago
Read 2 more answers
What modifier should you use on the members of a class so that they are not accessible to another class in a different package,
vova2212 [387]

The private modifier specifies that only other members of the same class can access the member. The protected modifier restricts access to the member to within its own package.

<h3>What are public and private modifiers?</h3>

The public access modifier permits code from both inside and outside the class to access the class's methods and properties, whereas the private modifier prevents outside code from accessing the class's methods and properties.

Thus, private modifier is the member.

For more details about private modifier, click here

brainly.com/question/15108837

#SPJ1

5 0
2 years ago
Other questions:
  • So for my Game Design class I have a quiz coming up...I was wondering if someone could answer some of these practice questions,
    7·2 answers
  • You are the IT administrator for a small corporate network. Recently, you added a web server that runs services that need to be
    12·1 answer
  • When planning a backup strategy, ideally one needs to prioritize important data and only back up what is absolutely necessary fo
    15·1 answer
  • ERP implementation probably will not require:
    8·2 answers
  • Which two standards below represent newer versions of stp??
    13·1 answer
  • You want to use a terminal program to terminal into a cisco router. what protocol should i use
    8·1 answer
  • Kelly is a college sophomore majoring in computer science. She is interested in gaining exposure to the most useful and current
    14·1 answer
  • What is wrong with my code...
    9·1 answer
  • Which option is created specifically for giving a slide presentation in front of an audience and works when the speaker is utili
    14·1 answer
  • Consider a pipelined processor with just one level of cache. assume that in the absence of memory delays, the baseline cpi of th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!