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

v-model life cycle

1622


What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?

1940


How does map works in java?

519


Where can I find jdk in my computer?

468


How do you use equal in java?

543






What is the use of bufferedreader?

532


What state does a thread enter when it terminates its processing in java programming?

578


What are the loops in java?

526


What does s mean in regex?

553


How do you insert a line break?

499


What are the super most classes for all the streams?

1175


What is the purpose of using bufferedinputstream and bufferedoutputstream classes?

554


What are static variables and functions?

628


How do you find the maximum number from an array without comparing and sorting?

641


What do you know about the garbage collector in java?

575