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
What is compiler and what its output.
What is the difference between the direct buffer and non-direct buffer in java?
What is the use of list in java?
What is multiple inheritance? Is it supported by java?
What do you mean by mnemonics?
Is empty list java?
how does multithreading take place on a computer with a single cpu? : Java thread
What is string made of?
How to create a base64 decoder in java8?
Can you explain inner class.
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
Difference between static synchronization vs. Instance synchronization?
Why set is used in java?
What do you mean Abstraction in java?
What is meant by binding in rmi?