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 the difference between static and dynamic binding of functions?
Is atoi safe?
What is copy constructor? Can we make copy constructor private in c++?
Define Virtual function in C++.
What can I safely assume about the initial values of variables which are not explicitly initialized?
What is the need of a destructor? Explain with the help of an example.
What is private, public and protected inheritance?
What is dev c++ used for?
What is the type of 'this' pointer? When does it get created?
Difference between pointer to constant vs. Pointer constant
Explain the difference between c++ and java.
What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?
Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.
What is static class data?
What is a container class? What are the types of container classes in c++?