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
Terri Duncan recommends following up after an interview in which way?
Varvara68 [4.7K]

Answer:

make contact in a way which fits the industry and is comfortable to you

Explanation:

Terri Duncan was a person that helped people going for interviews by offering them professional advice on how to compose and conduct themselves during an interview.

Terri Duncan also helps people going for interviews but providing them with the aid they need concerning what to say during an interview.

Terri Duncan recommends following up after an interview by making contact in a way which fits the industry and is also comfortable to you.

3 0
3 years ago
Molten metal is poured into the pouring cup of a sand mold at a steady rate of 400 cm3/s. The molten metal overflows the pouring
umka2103 [35]

Answer:

the proper diameter at its base so as to maintain the same volume flow rate is 1.6034 cm

Explanation:

Given the data in the question ;

flowrate Q = 400 cm³/s

cross section of the sprue is round

Diameter of sprue at the top d_top = 3.4 cm

Height of sprue = 20 cm = 0.2 m³

the proper diameter at its base so as to maintain the same volume flow rate = ?

first we determine the velocity at the sprue base

V_base = √2gh = √( 2×9.81×0.2) = √3.924 = 1.980908 m = 198.0908 cm

so, diameter of the sprue at the bottom  will be

Q = AV = [ (( πd²_bottom)/4) × V_bottom ]

d_bottom =  √(4Q/πV_bottom)

we substitute

d_bottom =  √((4×400)/(π×198.0908 ))

d_bottom =  √( 1600/622.3206)

d_bottom =  √2.571022

d_bottom =  1.6034 cm

Therefore, the proper diameter at its base so as to maintain the same volume flow rate is 1.6034 cm

8 0
3 years ago
A ladder logic program and the associated physical input/output components are given below. Lighting changes from full darkness
Katena32 [7]

Answer:

O2 is true.

Explanation:

8 0
4 years ago
A long iron rod (r 5 7870 kg/m3, cp 5 447 J/kg·K, k 5 80.2 W/m·K, and a 5 23.1 3 10–6 m2/s) with diameter of 25 mm is initially
MAXImum [283]

Answer:

Time required for iron rod surface temperature to cool to 200°C is 250 seconds.

Explanation:

7 0
4 years ago
What would be the most likely scale factor to use for an n-gauge model train setup? (An n-gauge layout uses locomotives that are
slega [8]
A or b for sure brother
8 0
3 years ago
Other questions:
  • 9) A construction company employs 2 sales engineers. Engineer 1 does the work in estimating cost for 70% of jobs bid by the comp
    11·1 answer
  • Design a half-wave recti er which provides a peak voltage of 15 V, and anaverage voltage of 3.8 V when driven by a 120 V (rms) a
    10·1 answer
  • Chemical manufacturers must present which information on the product's label?
    5·1 answer
  • Consider a Carnot heat-engine cycle executed in a closed system using 0.028 kg of steam as the working fluid. It is known that t
    11·1 answer
  • What Happens If A Sonic Boom Is Created?
    8·1 answer
  • A mason requires 12 mason-hours per 100 ft2 for the bottom 4 ft of wall, and a hod carrier requires 14.5 helper hours to mix the
    12·1 answer
  • Discuss with your neighbor your brain as a computer.
    14·1 answer
  • How much horse power does a Lamborghini have
    6·2 answers
  • The product of two factors is 4,500. If one of the factors is 90, which is the other factor?
    15·1 answer
  • Question 4(Multiple Choice Worth 2 points)
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!