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 / himesh mistry

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;


public class SecondMax {

/**
* @param args
*/
public static void main(String[] args) {
int[] numbers = {9,4,8,0,0,5,9,1,4,2};
Set arrSet = new HashSet();
for (int i=0;i<numbers.length;i++) {
arrSet.add(numbers[i]);
}
ArrayList s = new ArrayList(arrSet);
Collections.sort(s);

System.out.println("Second element : " +
s.get(s.size()-2));
}
}

Is This Answer Correct ?    16 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is reverse function?

1048


how can you catch multiple exceptions in java?

967


What is java console application?

941


Whats the difference between notify() and notifyall()?

967


What is the size of a string in java?

933


What are data types in oop?

992


Why is java logo a cup of coffee?

1067


Does java initialize arrays to zero?

959


What is ‘is-a ‘ relationship in java?

962


What is the difference between iterator and enumeration ?

951


Is linkedlist thread safe in java?

940


Is the empty set a singleton?

907


How do you break a loop?

921


Define the term string pool?

950


What is overloading and overriding in java?

1150