write java code to print second max number in the array
Answer Posted / himesh mistry
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class SecondMax {
/**
* @param args
*/
public static void main(String[] args) {
int[] numbers = {9,4,8,0,0,5,9,1,4,2};
Set arrSet = new HashSet();
for (int i=0;i<numbers.length;i++) {
arrSet.add(numbers[i]);
}
ArrayList s = new ArrayList(arrSet);
Collections.sort(s);
System.out.println("Second element : " +
s.get(s.size()-2));
}
}
| Is This Answer Correct ? | 16 Yes | 5 No |
Post New Answer View All Answers
Explain features of interfaces in java?
What are design patterns and please explain?
Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?
Where is java located?
Why charat is used in java?
What is the difference between abstract class and interface1? What is an interface?
what is method reference in java 8?
What is general methodology?
What is the difference between overriding & overloading?
What is sizeof () operator?
What is meant by data hiding in java?
What are identifiers in java?
Why packages are used?
Can a class extend more than one class?
Is java same as core java?