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

Can comments be nested?

1022


What are mutator methods in c++?

1158


How would you use qsort() function to sort an array of structures?

1116


What is difference between c++ 11 and c++ 14?

1088


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.

2583


Name the operators that cannot be overloaded in C++?

1044


Who invented turbo c++?

1064


What is an html tag?

1137


Write is a binary search tree? Write an algo and tell complexity?

1020


What is an adaptor class or wrapper class in c++?

1198


Describe the setting up of my member functions to avoid overriding by the derived class?

1130


How does c++ structure differ from c++ class?

1118


What is :: operator in c++?

1047


Explain about Garbage Collector?

1117


What are containers in c++?

988