Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method findClosest that takes an ArrayList of integers list and an int num as parameters. The method returns the index of the element

Write a method findClosest that takes an ArrayList of integers list and an int num as parameters. The method returns the index of the element in list that is closest to num and is smaller than or equal to num. If all elements are larger than num then the method should return -1.
For example, given list storing values [20,30,25,89,14],
findClosest(list,29) should return 2(index of element 25)
findClosest(list,50) should return 1(index of element 30)
findClosest(list,10) should return -1(no elements meet the conditions)

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

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

how would you have done things differently?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago