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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:40
1. the program must provide following functions to extract some statistics. note that the data_list parameter specified in these functions may be the same for all functions or different for different functions—that is your choice. a skeleton file is provided on mirmir. a) open_file()prompts the user to enter a year number for the data file. the program will check whether the year is between 1990 and 2015 (both inclusive). if year number is valid, the program will try to open data file with file name ‘year.txt’, where is the year. appropriate error message should be shown if the data file cannot be opened or if the year number is invalid. this function will loop until it receives proper input and successfully opens the file. it returns a file pointer and year. i. hint: use string concatenation to construct the file name b) read_file(fp)has one parameter, a file pointer read. this function returns a list of your choosing containing data you need for other parts of this project. c) find_average(data_list) takes a list of data (of some organization of your choosing) and returns the average salary. the function does not print anything. hints: i. this is not the average of the last column of data. it is not mathematically valid to find an average by finding the average of averages—for example, in this case there are many more in the lowest category than in the highest category. ii. how many wage earners are considered in finding the average (denominator)
Answers: 1
question
Computers and Technology, 24.06.2019 13:00
What are some websites that you can read manga (ex: manga rock)
Answers: 1
question
Computers and Technology, 24.06.2019 13:00
Which best describes the condition under which the unicode output is the same as plain text ?
Answers: 1
question
Computers and Technology, 24.06.2019 19:00
Which of the following "invisible" marks represents an inserted tab?
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, 18.09.2020 03:01
question
Health, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Chemistry, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Chemistry, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
English, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Physics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01
question
Mathematics, 18.09.2020 03:01