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
How do you square a number?
What is ide with example?
Which is faster string or stringbuilder?
Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?
what are Hostile Applets?
What is use of functional interface in java 8? Explain
What is the significance of continue jump statement? Explain with an example.
What is the purpose of static keyword in java?
Write a program to reverse a number in java?
Where is const variable stored?
What are the types of arrays in java?
Compare Mutex and Semaphore in java.
What are synchronized methods and synchronized statements in java programming?
What are the methods available in a class?
Is null or empty java?