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...

write java code to print second max number in the array

Answer Posted / raja ram

public class SecondMaximumNumber{
public static void main(String[] args){
int maxNumber = 0;
int secondMaxNumber = 0;
if(args.length == 0){
System.err.println("Number array is empty");
return;
}
for(int i=0; i < args.length; i++){
int currNumber = Integer.parseInt(args[i]);
if(maxNumber < currNumber){
secondMaxNumber = maxNumber;
maxNumber = currNumber;
}else if(secondMaxNumber < currNumber){
secondMaxNumber = currNumber;
}
}
System.err.println("Max. number is "+maxNumber);
System.err.println("Second Max. number is
"+secondMaxNumber);
}
}

Is This Answer Correct ?    7 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you square a number?

1270


What is ide with example?

968


Which is faster string or stringbuilder?

927


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

984


what are Hostile Applets?

2081


What is use of functional interface in java 8? Explain

1018


What is the significance of continue jump statement? Explain with an example.

1289


What is the purpose of static keyword in java?

963


Write a program to reverse a number in java?

1089


Where is const variable stored?

934


What are the types of arrays in java?

1090


Compare Mutex and Semaphore in java.

1005


What are synchronized methods and synchronized statements in java programming?

1022


What are the methods available in a class?

1081


Is null or empty java?

986