Write a method that takes two String
parameters, returns the number of times the
second string appears in the first string.
This method must be named
substringCount () and have two String
parameters. This method must return an
integer

Write A Method That Takes Two Stringparameters, Returns The Number Of Times Thesecond String Appears

Answers

Answer 1

A method that takes two String parameters, returns the number of times the second string appears in the first string.

public static int substringCount(String s1, String s2)
{
  int count = 0;
  int i = 0;
  while ((i = s1.indexOf(s2, i)) != -1)
  {
     count++;
     i += s2.length();
  }
  return count;
}

What is string?
A string is typically a sequence of characters in computer programming, either as a literal constant or as some sort of variable. The latter can either be fixed or its elements and length can be changed (after creation). A string is typically implemented as just an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. A string is generally thought of as a type of data. A string can also represent other sequence(or list) data types and structures, such as more general arrays. A variable declared to be a string may cause memory storage to be statically allocated for just a predetermined maximum length or utilise dynamic allocation to allow this to hold a variable number of elements, depending on this same programming language and specific data type used.

To learn more about string
https://brainly.com/question/28290531
#SPJ13


Related Questions

difference between electronic and non electronic components

Answers

Answer:

The working principle of both of them are same, i.e., uses the electrical energy for doing work. The major difference between the electrical and electronic devices is that the electrical devices convert the electrical energy into the other form of energy like heat, light, sound, etc

Other Questions
A 1.5 kg block is pulled across a horizontal surface that has a coefficient of kinetic friction of 0.60. What is the acceleration of the block? Step up an inequality for this situation below. Define your variable, but do not solve. (2 points 1 defined variable, 1 point correct inequality).Mr. Bass charges his music students $25 per lesson plus a recital fee of $50. How many lessons can a student take if they pay no more than $175? As the value of c increase toward infinity, what happens to the values of g(x) = 3x - 19 Find the Smallest number whichbeing added 28 toexactly divisable by 32, 36, 48and 96 A car traveling at 5m/s brakes and skids through a displacement of 6m. if it slows down at the rate of 2m/s/s, determine the length of time during which it breaks. how to correctly know how to quote a sentence which product characteristics would prompt the most intensive inspection? multiple choice question. low-cost, high-volume low-volume, high-cost moderate-cost, medium-volume Certain reactions in cells are endergonic. How do cells make those reactions proceed?. In a pack of Skittles, 20% are red. If 13 are red, how many skittles were in the entire bag? if a fair die is rolled, what is the probability of landing on an even number or a number greater than 2 I need asap thank you Mrs. Magdalino kept records on how much she spent on gasoline and the maintenance of her car. She found that it cost $485 to drive 500 mi in a month Find the cost per mileWrite an equation that relates the cost for gasoline and maintenance of a car to the number of miles m the car is driven. Use the equation to find the cost for driving 1200 miles. About how many miles are driven for a cost of $820? 13. In the figure, PSR is a straight line. Find RSQ and PQS. Which of the following equations are equivalent? Select three options. 2 + x = 5 x + 1 = 4 9 + x = 6 x + (negative 4) = 7 Negative 5 + x = negative 2 on the spreadsheet report, in the column for total fat (fat), you can see that brown rice (a whole grain) contains slightly more fat than white rice (a refined grain). what part of the rice grain accounts for this difference in fat content? Jennifer wants to improve her relationships with her customers. Which of the following measurements should she work on improving? A. gross margin B. sales per customer C. calls per period D. area coverage E. feedback rating pLS HURRY!!!This area model shows the quotient of 1/5+4What is the quotient?Enter your answer as a fraction in simplest from byfilling in the boxes. What provisions did Georgia's founding leader James Oglethorpe make to preserve the colony as a "society of hardworking people who would defend the British empire against invasion from the south"? the ceo of jnl corporation has been recently awarded 10,000 stock options. what are some factors that may influence the value of these options? multiple select question. the dividends paid by jnl in the past number of months to expiration the exercise price of the stock options the volatility of jnl stock if barbara falcon invests $16,751.84 now and she will receive $30,000 at the end of 10 years, what annual rate of interest will she be earning on her investment?