write java code to print second max number in the array
Answer Posted / laddu
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
public class Main1 {
public static void main(String[] args) {
Integer[] numbers = { 8, 2, 7, 1, 4, 9, 5};
int min = (int) Collections.min(Arrays.asList(numbers));
int max = (int) Collections.max(Arrays.asList(numbers));
ArrayList s = new ArrayList(Arrays.asList(numbers));
Collections.sort(s);
System.out.println("Second element : " + s.get(s.size()-2));
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How can we create a thread in java?
Write a java program that prints all the values given at command-line.
Difference between object and reference?
What is another word for methodology?
What is java reflection?
Why are generics used?
What is the base class of all exception classes?
Explain what pure virtual function is?
Is oracle charging for java?
what is use of functional interface in java 8?
What is main in java?
What are desktop procedures?
What restrictions are placed on method overloading in java programming?
What should I import for arraylist in java?
What is anagram in java?