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
Which is the correct APA format in books?​
Nina [5.8K]

Answer:

It includes the author's last name, the year, and  a page number. In the reference list, start with the author's last name and initials, followed by the year. The book title is written in sentence case

4 0
3 years ago
Read 2 more answers
What is the current DoD repository for sharing security authorization packages and risk assessment data with Authorizing officia
Tems11 [23]

Answer:

The answer is "Army Portfolio Management System".

Explanation:

The Army Way to solve Information-Technology (APMS-AITR) portfolio management registration for IT investment, IT capacity, and IT software was its single legal army registry.

Its main goal of IM/IT Management Of working capital and Corporate Finance is to prioritize IM/IT expenditure by evaluating and handling TRADOC as just an investment portfolio. The APMS was its main decision supporting instrument for military portfolio management.

8 0
3 years ago
What permissions should you assign a group if you want the group to have the ability to read, add, delete, execute, and modify f
ratelena [41]

Answer:

Modify is the correct answer to the following question.

Explanation:

If any person or user wants to read, delete, modify and execute the files then they have required the Modify permission. In other words, Modify permission provides the user to modify and delete the following files but they unable to delete subfolders because of the following permission.  

If they want then they have to change the permission by click right button from the mouse on the file or the folders which they want to change and then click on the properties from there they can change the permission.

7 0
4 years ago
The combination of two or more technologies or data feeds into a single, integrated tool is referred to as a _____.
igomit [66]
Mash-up, I believe, is the correct answer.
5 0
3 years ago
Compare the two types of formatting that IDE devices must go through. What is the primary difference between the two?
Andrei [34K]
A quick format<span> changes the file system while the </span>full format<span> also checks the </span>drive for bad sectors.  <span>The scan for bad sectors is the reason why the Full </span>format<span> takes twice as long as the </span>Quick format<span>. If you choose the </span>Quick format<span> option, the </span>format<span> removes address files from the partition, but does not scan the disk for bad sectors.</span>
7 0
3 years ago
Read 2 more answers
Other questions:
  • If you want to copy a file from one folder to another , what would you do?
    15·1 answer
  • [15 points] 3.2 Lesson Practice (holy marry mother of joseph)
    7·1 answer
  • Motivation is best defined as
    9·2 answers
  • What is a piece of information sent to a function
    15·1 answer
  • Program: ASCII art (Python 3)1) Output this tree. 2) Below the tree (with two blank lines), output this cat. (3 pts) /\ /\ o o =
    8·1 answer
  • (a) How many copies of the book titled "The Lost Tribe" are owned by the library branch whose name is "Sharpstown"? (b) How many
    10·1 answer
  • PowerPoint SAM Capstone Project 1 can PLEASE someone do it for me I have some directions like steps and you just have to do it i
    10·2 answers
  • 0 -10°
    12·1 answer
  • IF YOU WANT NICELY ENGLISH MUSIC ADD MY W.h.a.t.s.A.p.p nomber <br>+60 199094836​
    5·1 answer
  • Can i have help for a ggogle class room
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!