write java code to print second max number in the array

Answers were Sorted based on User's Feedback



write java code to print second max number in the array..

Answer / rajesh s

If we give negative values, what would be the Rajaraman
code begaves????

Is This Answer Correct ?    0 Yes 1 No

write java code to print second max number in the array..

Answer / murali

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class SecondMax {
public static void main(String[] args) {
String [] str={"3","4","2","1"};
List<String> ls=Arrays.asList(str);
Collections.sort(ls);
System.out.println(ls.size()-1);

}

}

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

What are the types of methodology?

0 Answers  


When does Exception occurs?

3 Answers  


I want my class to be developed in such a way that no other class (even derived class) can create its objects. Define how can I do so?

0 Answers  


When we will use an Interface and Abstract class?

9 Answers  


what is dynamic method dispatch ?

27 Answers   Fidelity, MUET, SDSF,


How the elements are organized in GridBagLayout?

1 Answers  


How can we make sure main() is the last thread to finish in java program?

0 Answers  


How do you use spaces in java?

0 Answers  


Mention a package that is used for linked list class in java.

0 Answers  


How many bytes is a string?

0 Answers  


Can we call virtual funciton in a constructor ?

0 Answers   XX,


Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods?

7 Answers   Ericsson,


Categories