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 collection api?
Can we declare a class as static?
What is the requirement of thread in java?
Is singleton set an interval?
What is arraylist e?
Explain about transient variables in java?
Why do we need singleton class?
How many types of exception can occur in a java program?
What are the two types of java?
why are wait(), notify() and notifyall() methods defined in the object class? : Java thread
What is a constructor, constructor overloading in java?
Which collection is thread safe in java?
why are there separate wait and sleep methods? : Java thread
How does list work in java?
What are the different types of inheritance in java?