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


Please Help Members By Posting Answers For Below Questions

What is collection api?

800


Can we declare a class as static?

783


What is the requirement of thread in java?

814


Is singleton set an interval?

707


What is arraylist e?

775


Explain about transient variables in java?

841


Why do we need singleton class?

724


How many types of exception can occur in a java program?

705


What are the two types of java?

750


why are wait(), notify() and notifyall() methods defined in the object class? : Java thread

735


What is a constructor, constructor overloading in java?

739


Which collection is thread safe in java?

725


why are there separate wait and sleep methods? : Java thread

769


How does list work in java?

689


What are the different types of inheritance in java?

755