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 a c++ object?
Can we inherit constructor in c++?
Where is atoi defined?
What is meant by forward referencing and when should it be used?
How can a called function determine the number of arguments that have been passed to it?
what is the difference between overloading & overriding? give example.
What is anonymous object in c++?
Can I run c program in turbo c++?
What is meant by entry controlled loop?
Where can I run c++ program?
What is guard code in c++?
Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300
What is the difference between set and map in c++?
What is isdigit c++?
What is the difference between an array and a list?