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, 21.06.2019 22:00
Determine which of the four levels of measurement (nominal, ordinal, interval, ratio) is most appropriate for the data below. internet speed levels of "fast comma " "medium comma " and "slow" choose the correct answer below. a. the ordinal level of measurement is most appropriate because the data can be ordered comma but differences left parenthesis obtained by subtraction right parenthesis cannot be found or are meaningless. nothing nothing nothing nothing nothing b. the interval level of measurement is most appropriate because the data can be ordered comma differences left parenthesis obtained by subtraction right parenthesis can be found and are meaningful comma and there is no natural starting point. c. the nominal level of measurement is most appropriate because the data cannot be ordered. nothing d. the ratio level of measurement is most appropriate because the data can be ordered comma differences left parenthesis obtained by subtraction right parenthesis can be found and are meaningful comma and there is a natural starting point.
Answers: 2
question
Computers and Technology, 22.06.2019 09:00
Which best describes the condition under which the unicode output is the same as plain text?
Answers: 3
question
Computers and Technology, 22.06.2019 10:40
When running anti-virus software , what could be a reason where recipitent is not guaranteed that data being streamed will not get interrupted?
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
Need asap assignment directions: think of an organization (business, religious institution, volunteer organization, sports team) with which you have been involved. imagine outfitting it with an it infrastructure. prepare a plan for what you would do to support outfitting it. draw a map of a network connecting all the individuals, give them pcs and printers, and lay out the design as best you can. the purpose is to begin working with these concepts, not to build a perfect network.
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, 04.02.2022 17:10
question
Mathematics, 04.02.2022 17:10
question
English, 04.02.2022 17:10
question
Computers and Technology, 04.02.2022 17:10
Questions on the website: 13722361