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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started