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
What is the difference between public, private, protected, and friend access?
Differentiate between stringbuffer and stringbuilder in java.
How many types of parsers are there?
How to create a thread in java?
What are loops in java?
What is the difference between procedural and object-oriented programs?
what is the difference between process and thread? : Java thread
What is the difference between the prefix and postfix forms of the ++ operator?
What are the differences between throw and throws?
Why you should not use singleton?
Is java 11 paid version?
Why is inheritance used in java?
What is the importance of finally block in exception handling?
What is java argument list?
What is fail first in java?