Question: Consider the following instance variable and incomplete method. The method is intended to return a string from the array words that would be last alphabetically.


Consider the following instance variable and incomplete method. The method is intended to return a string from the array words that would be last alphabetically. private String[] words; public String findLastWord () {/ missing implementation / \} Assume that words has been initialized with one or more strings containing only lowercase letters. Which of the following code segments can be used to replace / * missing implementation * / so that findLastword will work as intended? A) int maxIndex =0; for (int k=0;k 0 ) {maxIndex=k; } return words [maxIndex]; B) int maxIndex =0; for (int k=1;k 0 ) \{ max Index =k; \} \} return words [max Index] ; C) int maxIndex =0; for (int k=1;k 0 ) \{ maxIndex =k; \} D) return maxIndex; String maxWord = words [0]; for (int k=1;k0 ) { maxWord =k; \} return maxWord; E) String maxWord = words [0]; for (int k=1;k 0 ) \{ maxWord= words [k]; \} \} |return maxword
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
