Java writing algorithms question. The question says return the minimum value in
ID: 3810240 • Letter: J
Question
Java writing algorithms question. The question says return the minimum value in the input arraylist and we are given static double Q1(ArrayList input) {
NEED answer to this question here is my attempt and idk what to return or how to do loop I'm stuck and need correct written code!
1 import java.util.ArrayList; 3 public class Algorithms Lecture1 6 5 points 7e static double Q1 (Array List Double input) return the minimum value in the input ArrayList 9 Array List Double values new A Double 10 double m Values 1.0 input. .size 11 values add(my values); 12 double mi Double POSITIVE INFINITY 13 for (double number values 14 if( number mln min number 15 16 return min 18 19 20 21 public static void main(String args) t 22 23 24 25Explanation / Answer
AlgorithmLecture1.java
import java.util.ArrayList;
public class AlgorithmLecture1 {
static double Q1(ArrayList<Double> input){
Double minValue = input.get(0);
for(Double d : input){
if(minValue>d){
minValue = d;
}
}
return minValue;
}
public static void main(String[] args) {
ArrayList<Double> input = new ArrayList<Double> ();
input.add(30.0);
input.add(33.0);
input.add(23.0);
input.add(20.0);
input.add(50.0);
System.out.println("Min value: "+Q1(input));
}
}
Output:
Min value: 20.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.