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
Alla [95]
3 years ago
9

Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a

nd "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".
Computers and Technology
1 answer:
Alexxandr [17]3 years ago
8 0

Answer:

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".

Explanation:

The main issue with the first code segment is the way how the if else if condition are arranged. The "pea" is checked at the earliest time in the first code segment and therefore so long as there is the "pea" exist in the string (regardless there is pear or pearl exist in the string as well), the if condition will become true and display "pea" to terminal. This is the reason why the code segment 1 only work for the values of str that contain "pea".

You might be interested in
When writing professional emails, it is okay to use emoticons and
nekit [7.7K]

Answer:

False

Explanation:

8 0
3 years ago
Read 2 more answers
How to share excel file for multiple users office 365?.
Sholpan [36]

Answer:

You would need that person email to share it with them.

5 0
2 years ago
Read 2 more answers
2. Can you see any pitfalls or disadvantages to using Feedly to organize your online content sources?
Sergio039 [100]

Answer:

I think the disadvantages of using feedly is that people might now like switching over to use that or might not understand it.

8 0
3 years ago
What is the processing speed of the first generation computer ?
Hoochie [10]

Answer:

Millisecond

Explanation:

We might know millisecond is very small and it is

not used now as computer speed

5 0
3 years ago
What special identity group is typically used when a user accesses an FTP server that doesn't require user account logon?
Rainbow [258]

Answer:

The correct answer to the following question will be "​Anonymous logon".

Explanation:

  • Windows would never let anyone sign in interactively with an anonymous logon to the device, a person who has linked to the device without a login and password being given.
  • So they won't have to verify to an account of the user just whether you are running any shares.r document, let everyone log into the machine collaboratively with such a logon.

Therefore, Anonymous logon is the right answer.

4 0
4 years ago
Other questions:
  • When a program lets the user know that an invalid choice has been made, this is known as:?
    6·1 answer
  • Consider the following network: proxy-cache On average there are 35 objects downloaded per second, and the average object size i
    14·1 answer
  • A java program that calculates the balance of three months of $1000 and interest rate 6%
    9·1 answer
  • In the United States, everyone is guaranteed work true or false
    13·1 answer
  • Which bitwise operation has the same effect as multiplying a by 16?
    6·2 answers
  • The primary reason for a company to outsource jobs is to
    8·2 answers
  • If a user inserts a piece of clip art over some text but does not want the art to block the text, the user should select
    14·2 answers
  • Write a full class definition for a class named Player, and containing the following members:
    13·1 answer
  • Portable Document Format is a proprietary document file type created by Adobe Systems that is compatible with most computer syst
    7·1 answer
  • Which of the following safety and privacy features is not included in a P2P app or service?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!