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 arguments in java?
Why is the type for real numbers called double?
How to sort an unsorted array in java?
Differentiate between class and structure.
What is static variable with example?
What is meant by flickering?
How many bytes is 255 characters?
What is the maximum size of byte array in java?
Hi i am creating desktop application in that i want calling to mobile number. i have java telephone api (JTAPI) but i dont understand how it configure & use plese help me
How do you declare a variable?
Does constructor return any value?
Why object class is super class for every class in java?
How can constructor chaining be done by using the super keyword?
Why for each loop is used?
What are the kinds of polymorphism?