Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Find the second maximum in an array?

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


Please Help Members By Posting Answers For Below Questions

What is command line arguments in C++? What are its uses? Where we have to use this?

1174


What are the effects after calling the delete this operator ?

989


Why do we need templates?

947


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

946


Define whitespace in C++.

1143


How can I learn c++ easily?

1015


What is meant by const_cast?

1070


What happens when the extern "c" char func (char*,waste) executes?

1019


What does #define mean in c++?

1185


Does c++ support exception handling?

1002


Can you please explain the difference between overloading and overriding?

1024


What are formatting flags in ios class?

1189


What is the difference between an array and a list?

975


What is the use of default constructor?

1038


What is buffering in c++?

1013