Answer Posted / gang
public void getSecondMax(double[] arr){
double fmax, smax;
fmax=arr[0];
smax=arr[1];
for (int i = 1; i < arr.length; i++) {
if (arr[i]>fmax){
smax = fmax;
fmax = arr[i];
}
else if (arr[i]>smax)
smax = arr[i];
}
System.out.println("The 1st
highest="+fmax+"\t"+"The 2nd highest="+smax);
}
Note that it would not work if the array's size is only 1.
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
What is command line arguments in C++? What are its uses? Where we have to use this?
What are the effects after calling the delete this operator ?
Why do we need templates?
Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
Define whitespace in C++.
How can I learn c++ easily?
What is meant by const_cast?
What happens when the extern "c" char func (char*,waste) executes?
What does #define mean in c++?
Does c++ support exception handling?
Can you please explain the difference between overloading and overriding?
What are formatting flags in ios class?
What is the difference between an array and a list?
What is the use of default constructor?
What is buffering in c++?