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

What is the difference between public, private, protected, and friend access?

995


Differentiate between stringbuffer and stringbuilder in java.

984


How many types of parsers are there?

967


How to create a thread in java?

1089


What are loops in java?

1172


What is the difference between procedural and object-oriented programs?

937


what is the difference between process and thread? : Java thread

931


What is the difference between the prefix and postfix forms of the ++ operator?

974


What are the differences between throw and throws?

1035


Why you should not use singleton?

926


Is java 11 paid version?

929


Why is inheritance used in java?

1068


What is the importance of finally block in exception handling?

964


What is java argument list?

889


What is fail first in java?

1094