Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Is empty .java file name a valid source file name?

1058


What is data structure in java?

932


What is object in java?

918


Can we use a default constructor of a class even if an explicit constructor is defined?

1047


Can we clone singleton object?

1007


What is the meaning of variables in research?

975


What is unmodifiable collection in java?

859


What is ‘has a’’ relationship in java?

1151


What do you understand by overloading and overriding in java?

1011


What is string literal in java?

992


What is meant by call by reference?

944


How do you write a scanner class in java?

948


What is string builder?

836


What are different types of control structures?

917


How do I compare two strings in word in java?

934