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 / ibrahim

import java.util.ArrayList;
public class maxSec {

public static void main(String[] args) {
int maxFi=0;
int maxSe=0;
ArrayList<Integer> arl=new ArrayList<Integer>();

arl.add(4); arl.add(8); arl.add(2);
arl.add(6); arl.add(7); arl.add(8);

for(int i=0; i<arl.size(); i++){
if (maxFi< arl.get(i))
maxFi= arl.get(i);
}

for(int i=0; i<arl.size(); i++){
if (maxSe <arl.get(i)){
if (arl.get(i)<maxFi ){

maxSe=arl.get(i);
}
}
}
System.out.println(maxFi);
System.out.println(maxSe);

}

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you decide when to use arraylist and linkedlist?

941


Can we declare register variable as global?

893


explain the difference between jdk and jvm?

929


What is mean by collections in java?

1082


What is the significance of java packages?

1064


Is jdk required on each machine to run a java program?

1211


Explain how hashmap works?

1004


How do you initialize an arraylist in java?

974


What is the full meaning of java?

992


Explain illegalmonitorstateexception and when it will be thrown?

1034


What is the difference between super class & sub class?

1075


What is locale?

978


Why is string buffer better than string ?

1038


What are the advantages of assembly language?

871


What is Mutex (Mutual Exclusion Object) ?

1078