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
Explain binary search.
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
What is an operator function? Describe the function of an operator function?
Why can’t you call invariants() as the first line of your constructor?
What is while loops?
Explain Memory Allocation in C/C++ ?
Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).
Can a Structure contain a Pointer to itself?
How many keywords are used in c++?
What is the sequence of destruction of local objects?
Keyword mean in declaration?
What is c++ & why it is used?
What is a container class? What are the types of container classes in c++?
What it is and how it might be called (2 methods).
What is the rule of three?