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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:30, Nason156
What are some ways to use a range name in a formula? check all that apply. in the defined names group, click use in formula, and then select the desired name. begin typing the name in the formula, select a name from the autocomplete list, and use the arrow keys and tab key to enter the name in the formula. begin typing the formula, and then click and drag with the mouse to select the cells to include in the formula. right-click one of the cells in the range. click formula options, and use the dialog box to add the name.
Answers: 1
image
Computers and Technology, 23.06.2019 02:30, chaaaa
People with high self-esteem: accept their strengths and weaknesses. believe that failed experiences are failures of their whole self. feel good about who they are only when they reach total success. need positive external experiences to counteract negative feelings that constantly plague them.
Answers: 1
image
Computers and Technology, 23.06.2019 10:00, lamanihill
Now, open this passage to read about fafsa requirements. describe the information you will need to provide in order to complete a fafsa. list at least three of the required documents you must include.
Answers: 3
image
Computers and Technology, 23.06.2019 17:00, kyleemarie2003
Companies that implement and apply an information system effectively can create
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 in other subjects: