Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

What impresses you the most?

Answered: 1 week ago