subject

Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", and "pearl" that occur in String str. For example, if str has the value "the pear in the bowl", the code segments should both print "pear" and if str has the value "the pea and the pearl", the code segments should both print "pearl". Assume that str contains at least one instance of "pea".

I.

if (str. indexOf("pea") >= 0)

{

System. out. println("pea");

}

else if (str. indexOf("pear") >= 0)

{

System. out. println("pear");

}

else if (str. indexOf("pearl") >= 0)

{

System. out. println("pearl");

}

II.

if (str. indexOf("pearl") >= 0)

{

System. out. println("pearl");

}

else if (str. indexOf("pear") >= 0)

{

System. out. println("pear");

}

else if (str. indexOf("pea") >= 0)

{

System. out. println("pea");

}

Which of the following best describes the output produced by code segment I and code segment II?

Both code segment I and code segment II produce correct output for all values of str.

Neither code segment I nor code segment II produce correct output for all values of str.

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pear" but not "pearl".

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pearl".

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
Ulia is planning to attend the same private four-year college her parents attended. she wants to save at least $18,000 in four years to contribute to her college education. which monthly deposit amounts can julia use to achieve her goal? check all that apply.
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Verify each identity[tex] \frac{csc}{cot \: x \: + \: tan \: x} = cos \: x[/tex]
Answers: 1
question
Computers and Technology, 24.06.2019 12:10
What is it called during the editing process when the processor ensures that a character holding a coffee mug from one angle is holding the same mug in the same way when the shot switches to another camera at another angle? cinematography continuity technology prop use
Answers: 1
question
Computers and Technology, 24.06.2019 18:20
Use a while-end loop in a script file to calculate the sum of the first n terms of the series: summation sign on the top n bottom k=1 : )^k * k^2 +5k)/3^k show the script file and the two results of n = 10 and n = 20.
Answers: 2
You know the right answer?
Consider the following two code segments, which are both intended to determine the longest of the th...
Questions
question
Mathematics, 19.11.2019 06:31
question
Mathematics, 19.11.2019 07:31
question
History, 19.11.2019 07:31
question
Mathematics, 19.11.2019 07:31
Questions on the website: 13722360