Question: [JAVA] Hi, I have a homework problem that requires me to create a method that takes in a HashMap and returns a double. The method
[JAVA] Hi, I have a homework problem that requires me to create a method that takes in a HashMap and returns a double. The method will return the maximum result (do not return the original value) of taking the cosine of each value from the input while considering only negative numbers from the inputs. Here's what I have so far, I am just stuck on how to return the greatest negative number. Thank you in advance for the help!!
public static double q2(HashMap hMap1) {
double getCosine = 0.0;
double getIndexValue = 0.0;
double checkValue = 0.0;
for (Map.Entry entry1 : hMap1.entrySet()) {
getIndexValue = entry1.getValue();
getCosine = Math.cos(getIndexValue);
if (getIndexValue < 0.0) {
checkValue = getCosine;
}
}
return checkValue;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
