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
Can we override protected method in java?
Is math an abstract class in java?
What is palindrome in java?
What is the mapping mechanism used by java to identify IDL language?
When would you use a static class?
What is an error in java?
How to avoid memory leak in java?
Can an interface have a constructor?
What are the advantages of inner classes?
what is interface in java? Explain
Can you pass by reference in java?
How much ram can a 64 bit processor theoretically?
What does the “final” keyword mean in front of a variable? A method? A class?
What is a programming object?
Why we use methods in java?