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 are the important differences between c++ and java?
Why would you use pointers in c++?
Why is "using namespace std;" considered bad practice?
find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.
Is c++ built on c?
Does c++ have a hash table?
Can there be at least some solution to determine the number of arguments passed to a variable argument list function?
What do c++ programmers do?
How long will it take to learn programming?
What is the best c++ book for beginners?
How can I disable the "echo" feature?
What are static variables?
What is a set in c++?
What relational operators if statements in c++?
Write some differences between an external iterator and an internal iterator?