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, 21.06.2019 17:20
Find the inverse function of f(x)= 1+squareroot of 1+2x
Answers: 2
question
Computers and Technology, 22.06.2019 22:20
Avariable of the data type arrays is storing 10 quantities. what is true about these quantities? a. the quantities all have different characteristics. b. the quantities all have the same characteristics. c. five quantities have the same and five have different characteristics. d. it is necessary for all quantities to be integers. e. it is necessary for all quantities to be characters.
Answers: 2
question
Computers and Technology, 25.06.2019 09:00
Janet has to prepare a presentation on business strategies for work. which guideline should she follow to create an effective presentation? a. use a readable font b. use a multicolored background c. use a small, but stylish font d. include detailed text
Answers: 1
question
Computers and Technology, 25.06.2019 15:10
Write a program to compute the ideal weight for both males and females in java. according to one study, the ideal weight for a female is 100 pounds plus 5 pounds for each inch in height over 5 feet. for example, the ideal weight for a female who is 5'3" would be 100 + 3*5 = 115 pounds. for a male, the ideal weight is 106 pounds plus 6 pounds for each inch in height over 5 feet. for example, the ideal weight for a male who is 5'3" would be 106 + 3*6 = 124 pounds. your program should ask the user to enter his/her height in feet and inches (both as integers—so a person 5'3" would enter the 5 and the 3). it should then compute and print both the ideal weight for a female and the ideal weight for a male. the general outline of your main function would be as follows: (1) declare your variables (think about what variables you need—you need to input two pieces of information, then you need some variables for your calculations (see the following steps) (2) get the input (height in feet and inches) from the user (3) compute the total number of inches of height (convert feet and inches to total inches (note: 1 foot equal 12 inches and hence 5 feet equal 60 inches. (4) compute the ideal weight for a female and the ideal weight for a male (5) print the answers.
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, 30.11.2021 03:30
question
Mathematics, 30.11.2021 03:30