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
Can comments be nested?
What are mutator methods in c++?
How would you use qsort() function to sort an array of structures?
What is difference between c++ 11 and c++ 14?
Write a program to encrypt the data in a way that inputs a four digit number and replace each digit by (the sum of that digit plus 7) modulus 10. Then sweep the first digit with the third, second digit with the fourth and print the encrypted number.
Name the operators that cannot be overloaded in C++?
Who invented turbo c++?
What is an html tag?
Write is a binary search tree? Write an algo and tell complexity?
What is an adaptor class or wrapper class in c++?
Describe the setting up of my member functions to avoid overriding by the derived class?
How does c++ structure differ from c++ class?
What is :: operator in c++?
Explain about Garbage Collector?
What are containers in c++?