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
Hitman42 [59]
3 years ago
12

* Write a recursive function that finds the index of s2 in s1. Do not use any * string functions except for .length(), .equals()

, and .substring(). Do not use * any loops, or any data structures.
Engineering
1 answer:
ankoles [38]3 years ago
4 0

Answer:

public int indexOfStrings(String s1, String s2) {

if(s1.length() < s2.length())

return -1;

if(s1.substring(0, s2.length()).equals(s2))

return 0;

int index = indexOf(s1.substring(1), s2);

if(index == -1)

return -1;

return 1 + index;

}

Explanation:

First create the method indexOfStrings to receive 2 strings s1 and s2.

Then test with an 'if' statement to check if the length of s1 is less than s2. We hope to find the index s2 in s1 therefore s1 should be greater in length than s2. If this doesn't follow them it should return -1 showing negativity in the function.

Then with check using a substring () function with the endIndex as the length of s2 and beginIndex as 0, to see if the new substring of s1 is equal to string s2. If this true we return 0 and the method ends.

We the initialize index as integer, and repeat the function and insert the substring of s1 with a beginIndex of 1, and the second variable as s2.

We test to see if this index will be equal to -1(negative), if true we end the function.

Finally if all goes well the method returns 1 plus the index integer.

You might be interested in
If the slotted arm rotates counterclockwise with a constant angular velocity of thetadot = 2rad/s, determine the magnitudes of t
astraxan [27]

Answer:

Magnitude of velocity=10.67 m/s

Magnitude of acceleration=24.62 ft/s^{2}

Explanation:

The solution of the problem is given in the attachments

3 0
3 years ago
Can i have answer of this question please?
cestrela7 [59]

uh its a tough one mate

3 0
3 years ago
What are the minimum and maximum required footing projections for a concrete footing having a thickness of 8 inches
SpyIntel [72]

The minimum and maximum required footing projections for a concrete footing having a thickness of 8 inches will be 4 inches and 8 inches.

<h3>What is projection?</h3>

It should be noted that footing projections are important for construction purposes

In this case, the minimum and maximum required footing projections for a concrete footing having a thickness of 8 inches will be 4 inches and 8 inches.

Learn more about projection on:

brainly.com/question/3703881

#SPJ12

8 0
2 years ago
What kind of job does Malcolm have?
Effectus [21]
Huh? what do you mean?
8 0
4 years ago
Read 2 more answers
Write multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has
Slav-nsk [51]

Answer:

Explanation along with code and output results is provided below.

C++ Code:

#include <iostream>

using namespace std;

int main()

{

   int year;

   cout<<"Enter the car model year."<<endl;

   cin>>year;    

  if (year<=1969)

  {

cout<<"Few safety features."<<endl;

  }

else if (year>=1970 && year<1989)

{

cout<<"Probably has seat belts."<<endl;

}

else if (year>=1990 && year<1999)

{

cout<<"Probably has antilock brakes."<<endl;

}

else if (year>=2000)

{

cout<<"Probably has airbags."<<endl;

   }

   return 0;

}

Explanation:

The problem was to print feature messages of a car given its model year.

If else conditions are being used incorporate the logic. The code has been tested with several inputs and got correct output results.

Output:

Enter the car model year.

1961

Few safety features.

Enter the car model year.

1975

Probably has seat belts.

Enter the car model year.

1994

Probably has antilock brakes.

Enter the car model year.

2005

Probably has airbags.

5 0
4 years ago
Other questions:
  • Fictional Corp is looking at solutions for their new CRM system for the sales department. The IT staff already has a fairly heav
    10·1 answer
  • First step in solving frames in to solve support reactions when looking at the frame as a whole. a)- True b)-False
    9·1 answer
  • A missile flying at high speed has a stagnation pressure and temperature of 5 atm and 598.59 °R respectively. What is the densit
    12·1 answer
  • A system consists of N very weakly interacting particles at a temperature T sufficiently high so that classical statistical mech
    9·1 answer
  • What is the average linear (seepage) velocity of water in an aquifer with a hydraulic conductivity of 6.9 x 10-4 m/s and porosit
    13·1 answer
  • Two vertical, parallel clean glass plates are spaced a distance of 2mm apart. if the plates are placed in water, how high will t
    14·1 answer
  • 1) Each of the following would be considered company-confidential except
    10·1 answer
  • Examples of reciprocating motion in daily life
    14·1 answer
  • Random question, does anyone here use Lego, do not answer unless that is a yes
    15·2 answers
  • Two solid yellow center lines on a two-lane highway indicate:
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!