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

What is compiler and what its output.

1143


What is the difference between the direct buffer and non-direct buffer in java?

1023


What is the use of list in java?

980


What is multiple inheritance? Is it supported by java?

959


What do you mean by mnemonics?

1047


Is empty list java?

916


how does multithreading take place on a computer with a single cpu? : Java thread

1138


What is string made of?

950


How to create a base64 decoder in java8?

1051


Can you explain inner class.

1072


Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?

1104


Difference between static synchronization vs. Instance synchronization?

1104


Why set is used in java?

1002


What do you mean Abstraction in java?

1084


What is meant by binding in rmi?

1001