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
v-model life cycle
What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?
How does map works in java?
Where can I find jdk in my computer?
How do you use equal in java?
What is the use of bufferedreader?
What state does a thread enter when it terminates its processing in java programming?
What are the loops in java?
What does s mean in regex?
How do you insert a line break?
What are the super most classes for all the streams?
What is the purpose of using bufferedinputstream and bufferedoutputstream classes?
What are static variables and functions?
How do you find the maximum number from an array without comparing and sorting?
What do you know about the garbage collector in java?