Question: Java Program: Minimum Value Write a generic function FindSmallest() that returns the smallest value (minimum) in an ArrayList of numbers (Integers, Doubles, etc.) that is

Java Program: Minimum Value

Write a generic function FindSmallest() that returns the smallest value (minimum) in an ArrayList of numbers (Integers, Doubles, etc.) that is passed to it.

Hint: you will use the compareTo() method to compare the values in the function.

You will hardcode your ArrayLists.

For the sample code:

ArrayList one = new ArrayList(); one.add(4.5); one.add(45.2); one.add(14.5); one.add(3.14); one.add(4.5); one.add(450.0); System.out.println("The smallest value in: "+one+" is: "+FindSmallest(one)); 

The output should be:

The smallest value in: [4.5, 45.2, 14.5, 3.14, 4.5, 450.0] is: 3.14 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!