Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The method findLargest should return the largest of any number of double values. For example, the call findLargest (3.4, -2.6, 2.9) should return 3.4 and
The method findLargest should return the largest of any number of double values. For example, the call findLargest (3.4, -2.6, 2.9) should return 3.4 and the call findLargest (9.2, 17.6, 3.4, -2.6, 2.9) should return 17.6. Partial code to do this is given below:
double findLargest (double... values)
{
double max = values[0];
// New code goes here
return max;
}
What code will complete this method?
A)
for (double val: values)
{
if (val > max)
{
max = val;
}
}
B)
for (int i = 1; i < values.length; i++)
{
if (i > max)
{
max = i;
}
}
C)
for (double val:values)
{
if (values[val] > max)
{
max = values[val];
}
}
D)
for (int i = 1; i < values.length; i++)
{
if (values[i] > max)
{
max = i;
}
}
Please give an explanation!
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