subject
Computers and Technology, 05.05.2020 19:26 tay8556

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?

a) Both code segment I and code segment II produce correct output for all values of str.
b) Neither code segment I nor code segment II produce correct output for all values of str.
c) 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".
d) 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".
e) 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: 2

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 00:00
Consider the series where in this problem you must attempt to use the ratio test to decide whether the series converges. compute enter the numerical value of the limit l if it converges, inf if it diverges to infinity, minf if it diverges to negative infinity, or div if it diverges but not to infinity or negative infinity.
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
question
Computers and Technology, 24.06.2019 17:40
Pseudocode pld #6, pg. 117 start// declarations// number numbertoguess// number myguess; numbertoguess = 92// while myguess ! = numbertoguess// output " guess an integer number between 1 and 100"// input myguess// if (myguess == numbertoguess)// output "you guessed the correct number"// else// output "the number you guessed was incorrect. try again! "// end if// end while// output " for playing the guessing game. have a great day! "// stop
Answers: 3
question
Computers and Technology, 24.06.2019 21:00
When replacing a thermostat or water pump, coolant drained from the cooling system should be
Answers: 1
You know the right answer?
Consider the following two code segments, which are both intended to determine the longest of the th...
Questions
question
History, 09.02.2022 17:50
question
Mathematics, 09.02.2022 18:00
Questions on the website: 13722367