Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.List; import java.util.ArrayList; /* * * This program loops through an array list of strings and finds the longest string */ public class FindLongest

import java.util.List;
import java.util.ArrayList;

/*
*
*  This program loops through an array list of strings and finds the longest string
*/
public class FindLongest
{
  /*
   * Given the array list of strings, return the longest string
   */
public static String findLongest(ArrayList list)
{
//-----------Start below here. To do: approximate lines of code = 8
// loop through the list of strings and check to see if
  // the string length is > the current longest string. If so, update the
  // longest string length. Be sure to create a variable to hold the longest string itself
  // as well as the length













//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
ArrayList elems = new ArrayList();
String[] words = {"singapore", "cattle", "metropolitan", "turnstile", "city", "deviation"};
for (int i = 0; i < words.length; i ++)
{
elems.add(words[i]);
}
System.out.println(findLongest(elems));
System.out.println("Expected:metropolitan");
elems.clear();
System.out.println(findLongest(elems));
System.out.println("Expected:");
}
}


P.S: Please write the code as well as include screenshots for reference along with output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javautilList import javautilArrayList This program loops through an array list of strings and ... 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

A First Course In Probability

Authors: Sheldon Ross

9th Edition

978-9332519077, 9332519072

More Books

Students also viewed these Programming questions

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago

Question

The following sample observations were randomlyselected.

Answered: 1 week ago