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
Is c++ faster than c?
What are static type checking?
When does a 'this' pointer get created?
What does namespace mean in c++?
What are the advantages of using friend classes?
What is an accessor in c++?
What is do..while loops structure?
Why is c++ not purely object oriented?
Which sort does c++ use?
What is the best c++ compiler?
What is using namespace std in c++?
can any one help to find a specific string between html tags
which is changed to a sting..
weather.html looks (for location) is
Why do we use string in c++? What is scope operator in c++? How to allocate memory dynamically for a reference?