Question
JAVA- Implement the findShortest method to return the String with the shortest length stored in the parameter array named words (you may assume that words
JAVA-
Implement the findShortest method to return the String with the shortest length stored in the parameter array named words (you may assume that words is not empty). If several Strings have the same length it should print the first String in the list with the shortest length.
For example, if the following array were declared:
String[] wordList = {"high", "every", "nearing", "checking", "food ", "stand", "value", "best", "energy", "add", "grand", "notation", "abducted", "food ", "stand"};
The method call findShortest(wordList) would return the String "add".
Use the runner class to test this method: do not add a main method to your code in the U6_L3_Activity_One.java file or it will not be scored correctly.
Hint - this algorithm is very similar to the algorithms you have seen to find maximum/minimum values in unit 4. You need a variable which will keep track of the shortest word in the array (either directly or as the array index of that word). Start this variable off with a sensible value, update it whenever a shorter word is found, then return the shortest word at the end.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started