Program to print second largest number in an array without sorting

2ndlr

 
public class SecLargest {

public static void main(String[] args) {
// TODO Auto-generated method stub

int[] num = {15000,9,80,7,8000,0,12000,3,5,2500,4000,5099};
int k = num[0];

// loop for largest number
for(int i=0;i<num.length;i++)
{
if(num[i]>k)
{
k=num[i];
}
}

int t;
if(k!=num[0]) // if k is not first element of array
{
t = num[0];
}
else // if k first element of array
{
t = num[1];
}

// loop for 2nd largest number
for(int i=0;i<num.length;i++)
{
if(num[i]>t && num[i]!=k)
{
t = num[i];
}
}

//System.out.println(k); // largest number
System.out.println(t); // 2nd largest number

}

}

You may also like...

1 Response

  1. Rishi says:

    Awesome one……removed the hidden bug for the first element…..Great Job!!!

  2. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Thank you, An abundance of content.

    http://canadianpharmaciesnnm.com/
    mexican pharmacies shipping to usa
    canadian pharmacy online
    canadian drug stores online
    canadian pharmacies without an rx

  3. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Point very well used!.
    http://canadianpharmacymim.com/
    canadian pharmacy online london drugs canada pharmacy near me canadian pharmacies online
    pharmacy cost comparison
    pharmacy near me
    no 1 canadian pharcharmy online
    prescription drugs online without
    canada drug pharmacy
    canada pharmacies online prescriptions

  4. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Thanks a lot. I like this.
    http://talahicc.com/
    pharmacy price comparison canadian cialis online pharmacy northwest pharmacy
    best online international pharmacies
    walgreens pharmacy
    board of pharmacy
    best online canadian pharcharmy
    drug costs
    mexican pharmacy online

  5. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You have made your point quite well!.
    http://canadianpharmaciesnnm.com/
    canadian online pharmacies canada pharmaceutical online ordering mexican pharmacies online canadian pharmacies-24h
    canada drugs pharmacy
    canadian pharmacy online canada
    overseas pharmacy forum
    drug costs
    pharmacy cost comparison
    northwestpharmacy

  6. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You have made the point.
    http://canadianpharmacyntx.com/
    canadian drug store northwestpharmacy buy drugs online online pharmacies of canada
    canadapharmacy
    mexican pharmacy online medications
    prescription drugs online without
    best online pharmacy
    canadian rx
    canadian prescription drugstore

  7. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You definitely made the point!
    http://canadianpharmacymim.com/
    canada pharmacy aarp approved canadian online pharmacies trusted overseas pharmacies [url=http://talahicc.com/]top rated canadian pharmacies online[/url]
    canada pharmacy online
    drug stores near me
    internet pharmacy
    compare rx prices
    web medical information
    canada pharmacy online orders

  8. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Many thanks, A good amount of posts.
    http://talahicc.com/
    online prescription drugs canadian pharmacy online 24 hour pharmacy global pharmacy canada
    rx price comparison
    cheap drugs online
    legitimate canadian mail order pharmacies
    canada meds
    pharmacy online store
    safeway pharmacy

  9. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You said it adequately.!
    http://canadianpharmacysilo.com/
    canadapharmacyonline.com online pharmacies canada prescription drugs canada canadian pharmacies-24h
    northwest pharmacy canada
    prescription online
    canada drugs pharmacy
    best online pharmacy
    online pharmacy canada
    buy prescription drugs canada

  10. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Thanks a lot. An abundance of facts.
    http://talahicc.com/
    legitimate canadian mail order pharmacies canadian pharcharmy canadian pharmacy meds canadianpharmacy
    prescription drug price comparison
    pharmacy online
    canadian drugstore online
    canadian pharmacies that ship to us
    web medical information
    walgreens pharmacy

  11. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually expressed it terrifically.
    http://canadianpharmacysilo.com/
    canadian drugstore reviews canadian online pharmacy cialis canadian pharmacy canada drugs online
    canadian prescription drugs
    visit poster’s website
    buying drugs canada
    canada drug pharmacy
    buy online prescription drugs
    pharmacy without dr prescriptions

  12. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually explained it well.
    http://canadianpharmacymim.com/
    prescription drugs without prior prescription northwest pharmacy canada pharmacy mexican pharmacies shipping to usa
    canadian drugs without prescription
    canada pharmacy
    the canadian pharmacy
    buying prescription drugs canada
    discount prescription drug
    canadian pharmacy king

  13. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You reported it exceptionally well!
    http://talahicc.com/
    canadian pharcharmy online canada drug best canadian pharmacies canadian pharmaceuticals online
    canadian pharmacies without prescriptions
    international pharmacies that ship to the usa
    canadian meds
    reputable canadian mail order pharmacies
    canada drugs
    best non prescription online pharmacies

  14. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    With thanks. Lots of forum posts.
    http://canadianpharmacysilo.com/
    candrugstore com canadian viagra online pharmacies no prescription canadian drugs
    canada pharmacy no prescription
    canada pharmacy
    prescription drug assistance
    buy online prescription drugs
    online drugstore
    overseas pharmacies

  15. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Whoa lots of fantastic data!
    http://canadianpharmacymim.com/
    best online international pharmacies canadian online pharmacies canadian pharmacies that ship to us canada drugs online
    canada pharmacies without script
    no prescription online pharmacy
    canadian cialis
    canada drugs online
    <a href="http://www.nationwidemarketing.com/blog/?form2mailerror&inquiry=Business+Development&fname=LucasCep&lname=LucasCep&email=lucasBrori%40gmail.com&company=google&phone1=84496129645&phone2=88451916927&phone3=83163924588&comments=+This+is+nicely+put.+%21+http://canadianpharmaciescubarx.com/+legitimate+canadian+mail+order+pharmacies+%3Ca+href=%22http://canadianpharmaciescubarx.com/%22%3Ecanadian+pharmacies%3C/a%3E+drugs+without+prescription+%3Ca+href=http://talahicc.com/%3Enorth+west+pharmacy+canada%3C/a%3E?form2mailerror&inquiry=Business Development&fname=Howardcoesy&lname=Howardcoesy&email=zittel020eejf@songwriter.net&company=google&phone1=85884611389&phone2=84244143285&phone3=87787558965&comments=You actually reported that well. http://canadianpharmaciescubarx.com/ best online pharmacy aarp approved canadian online pharmacies drugs without prescription global pharmacy canada pharmacy price compare cialis online online canadian pharcharmy get prescription online canada pharmacy canadian pharmacy“>canadian family pharmacy
    prescription online

  16. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Seriously loads of good facts.
    http://talahicc.com/
    canadapharmacy canadian drugs canadian pharmacy reviews canadian pharmacies without an rx
    discount prescription drug
    king pharmacy
    best canadian prescription prices
    buy prescription drugs canada
    canadian pharmacies shipping to usa
    pharmacy prices compare

  17. HowardWhivy says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Fantastic information, Many thanks.
    http://canadianpharmacymim.com/
    canadian drug mexican pharmacies shipping to usa canada pharmacy online reviews northwestpharmacy
    canada drug prices
    canadian pharmacies online prescriptions
    online pharmacy canada
    no prior prescription required pharmacy
    canada drugs online
    online pharmacy no prescription

  18. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Whoa quite a lot of wonderful info.
    http://canadianpharmaciescubarx.com/
    meds online canadian pharmacies-24h web medical information canadian pharmacy
    canadian drug store
    compare rx prices
    canada pharmacy online
    canadian pharmacy
    prescription drug assistance
    canadapharmacyonline com

  19. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually stated it fantastically!
    http://talahicc.com/
    canadapharmacyonline com top rated canadian pharmacies online canadian pharmacy king canadian pharmacies
    canada online pharmacy
    overseas pharmacies
    online pharmacies no prescription
    canadian meds
    canada drugs online pharmacy
    online discount pharmacy

  20. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Nicely put, Thanks a lot.
    http://canadianonlinepharmacynnm.com/
    online pharmacies canada canadian pharmacies-24h medical information online north west pharmacy canada
    pharmacies near me
    canada pharmacy online no script
    canadian viagra
    board of pharmacy
    canada pharmacy online no script
    canada pharmacy

  21. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You made your position extremely well.!
    http://canadianpharmaciescubarx.com/
    canada pharmacies online prescriptions online pharmacies of canada mail order pharmacy canada pharmacy online
    pharmacy tech
    pharmacy prescription
    northwest pharmacy canada
    mexican pharmacies online
    canadian online pharmacy reviews
    online canadian discount pharmacy

  22. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Thanks a lot. I like it.
    http://canadianonlinepharmacynnm.com/
    pharmacies in canada canada pharmacy medical information online canadian cialis
    prescription drugs without prior prescription
    no prescription pharmacies
    buy prescription drugs online
    pharmacy online store
    prescription drug price comparison
    canadian pharmacies online

  23. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Excellent knowledge. Appreciate it.
    http://canadianpharmacymim.com/
    canadian pharmacy 365 canada pharmaceutical online ordering canadian drug stores online canadian online pharmacy
    approved canadian pharmacies online
    no prescription online pharmacy
    online drugs
    best canadian online pharmacy
    pharmacy price comparison
    canada online pharmacy

  24. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Well spoken indeed! .
    http://canadianpharmacyntx.com/
    canadian prescription drugstore london drugs canada buy drugs online canadian online pharmacies
    pharmacy cost comparison
    canadapharmacy
    canadian pharmacy no prescription
    best online pharmacy stores
    canadian discount pharmacy
    candrugstore com

  25. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You mentioned it fantastically.
    http://canadianpharmacyntx.com/
    mail order pharmacies canada pharmaceutical online ordering prescription drug price comparison canadian online pharmacy
    mexican pharmacies
    online pharmacy
    buy online prescription drugs
    rx price comparison
    discount prescription drug
    canadian pharmacy meds

  26. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Thanks! Plenty of tips.
    http://canadianpharmaciesnnm.com/
    canada pharmacy online no script canadian online pharmacies best online international pharmacies canadian pharmacies without an rx
    online pharmacy usa
    canada pharmacies
    best online pharmacy
    canadian pharmacy no prescription needed
    prescription online
    best online pharmacies canada

  27. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Really loads of beneficial tips.
    http://talahicc.com/
    legitimate canadian mail order pharmacies trust pharmacy canada canada pharmacies prescription drugs canada drugs
    price prescription drugs
    canadian drug stores online
    canadian drugstore reviews
    buy cialis
    canadian pharmacies online prescriptions
    pharmacy tech

  28. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually said that effectively.
    http://www.canadianpharmacymsn.com/
    onlinecanadianpharmacy.com canada pharmaceutical online ordering pharmacies in canada global pharmacy canada
    rx pharmacy
    canadian pharmacy without prescription
    canadian pharma companies
    canadian pharmacies online prescriptions
    best canadian prescription prices
    best online canadian pharcharmy

  29. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You said it nicely.!
    http://canadianpharmacymim.com/
    canada drugs pharmacy canadian online pharmacy compare prescription prices canada online pharmacies
    no prior prescription required pharmacy
    online pharmacy
    prescription drug
    canadian pharmacies top best
    prescription drug price comparison
    drugs for sale

  30. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually mentioned it really well.
    http://canadianpharmacymim.com/
    costco pharmacy pricing canadian cialis canadian rx canadian pharmacies online
    king pharmacy
    online pharmacy canada
    canada online pharmacy
    online pharmacy no prescription
    canadian prescription
    buy prescription drugs canada

  31. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Truly loads of good tips!
    http://canadianpharmaciesnnm.com/
    mail order pharmacies canadian online pharmacy best online pharmacies no prescription trust pharmacy canada
    prescription drugs without prior prescription
    canadianpharmacy
    pharmacy near me
    buy prescription drugs online
    candrugstore com
    overseas pharmacy forum

  32. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually mentioned that well!
    http://talahicc.com/
    canadian pharmacies online canada drugs drug prices comparison northwestpharmacy
    drug prices comparison
    approved canadian pharmacies online
    compare prescription prices
    online canadian pharmacies
    international pharmacies that ship to the usa
    discount prescription drugs online

  33. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    With thanks! I appreciate it!
    http://canadianpharmaciescubarx.com/
    buy prescription drugs without doctor canadian pharmaceuticals online pain meds online without doctor prescription online pharmacies of canada
    best online pharmacies no prescription
    overseas pharmacy forum
    mexican pharmacy online medications
    legitimate online pharmacies
    no 1 canadian pharcharmy online
    online pharmacies

  34. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You’ve made the point.
    http://canadianonlinepharmacynnm.com/
    online canadian discount pharmacy canadian pharmacy online canadian drugstore reviews london drugs canada
    trusted overseas pharmacies
    price prescription drugs
    24 hour pharmacy
    compare prescription prices
    pharmacies in canada
    online canadian discount pharmacy

  35. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    This is nicely put! !
    http://canadianpharmacysilo.com/
    canadian drugstore online canada pharmacy online prescription drugs without doctor approval online pharmacies canada
    canadian online pharmacy reviews
    canadian pharmacy no prescription
    canadian prescriptions
    online pharmacies
    24 hour pharmacy
    prescription prices comparison

  36. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Reliable content. Thanks.
    https://nicktambone.com/
    prescription cost canadian online pharmacy canada drugs canadian pharcharmy
    prescription price comparison
    canadian pharmacy meds
    price prescription drugs
    best online pharmacies no prescription
    buying prescription drugs canada
    mexican pharmacies

  37. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Great data. Regards!
    http://talahicc.com/
    cialis online canadian cialis mexican online pharmacies canada pharmacy
    king pharmacy
    discount prescription drug
    canada pharmacy online orders
    pharmacies near me
    prescription without a doctor’s prescription
    canadian pharmacy 365

  38. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Kudos, Ample postings!
    http://talahicc.com/
    canadian drug stores online canadian pharmacies-24h rx pharmacy canadianpharmacy
    canadian drugs
    northwest pharmacy canada
    drugs for sale
    best canadian mail order pharmacies
    best non prescription online pharmacies
    most reliable canadian pharmacies

  39. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Seriously many of terrific tips!
    http://canadianonlinepharmacynnm.com/
    most reliable canadian pharmacies aarp approved canadian online pharmacies buy prescription drugs from canada canada pharmacy
    discount pharmacy
    online rx pharmacy
    canadian drug store
    internet pharmacy
    prescription without a doctor’s prescription
    online pharmacy usa

  40. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Useful info. Regards.
    http://canadianpharmaciescubarx.com/
    pharmacy online canadian pharmacies-24h mail order pharmacies canadian pharcharmy
    online pharmacy
    canadian pharma companies
    canadian discount pharmacy
    drug prices comparison
    best canadian prescription prices
    canada drug prices

  41. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Good postings. Thanks a lot!
    http://talahicc.com/
    candrugstore com canadian pharcharmy canada drugs online canadian cialis
    canadian pharmacy
    drug stores near me
    prescription drug assistance
    canadapharmacyonline.com
    24 hour pharmacy
    rx price comparison

  42. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Incredible lots of wonderful material!
    http://talahicc.com/
    24 hour pharmacy canadian pharmacy online discount pharmacy online canadian pharmacy
    canadian pharmacy viagra brand
    discount prescription drugs online
    meds online
    canadian drug stores online
    trust pharmacy canada
    pharmacy price comparison

  43. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Point clearly taken..
    http://canadianpharmaciesnnm.com/
    canada drug prices north west pharmacy canada no prescription online pharmacy canadian viagra
    global pharmacy canada
    reputable canadian mail order pharmacies
    best canadian mail order pharmacies
    canadian online pharmacy reviews
    northwest pharmacy canada
    best canadian prescription prices

  44. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You actually revealed this fantastically!
    http://canadianpharmacymim.com/
    safe canadian online pharmacies canadian pharmacy online northwest pharmacy canada top rated canadian pharmacies online
    canada pharmacies without script
    online pharmacies
    canada online pharmacy
    canadian drug
    prescription drug price comparison
    canadian online pharmacy

  45. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Tips well regarded!!
    http://canadianpharmacysilo.com/
    canadapharmacyonline com north west pharmacy canada international pharmacies that ship to the usa global pharmacy canada
    drugs without prescription
    discount prescription drugs online
    canada pharmacies online pharmacy
    online pharmacy
    canadian pharmacies online prescriptions
    canadian pharmacies

  46. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    With thanks, Great information.
    http://canadianpharmacymim.com/
    buy prescription drugs from canada canada online pharmacies canadian pharmacy 365 online pharmacies canada
    canadian discount pharmacy
    canadian viagra
    canada pharmacy
    overseas pharmacy forum
    24 hour pharmacy
    cheap canadian drugs

  47. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Awesome advice. Kudos.
    http://www.canadianpharmacymsn.com/
    canada pharmacy online canadian online pharmacy no prior prescription required pharmacy aarp approved canadian online pharmacies
    cheap canadian drugs
    approved canadian pharmacies online
    prescription drugs online without doctor
    canadian pharcharmy online
    canada drug prices
    canadian pharmacy without prescription

  48. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You said it nicely.!
    http://canadianpharmacymim.com/
    pharmacy online store canadian pharmacy online best canadian online pharmacy canada pharmacy online
    canadian pharmacy without prescription
    buy cialis
    overseas pharmacy forum
    northwestpharmacy
    prescription without a doctor’s prescription
    best online international pharmacies

  49. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You have made your point!
    http://canadianpharmaciescubarx.com/
    pain meds online without doctor prescription north west pharmacy canada canadian pharmacy online canada canadian online pharmacies
    trust pharmacy canada
    prescription cost comparison
    legitimate online pharmacies
    pharmacy online mexico
    drugs from canada
    online drugstore

  50. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Seriously a lot of great knowledge!
    http://canadianpharmacymim.com/
    canada pharmacies prescription drugs top rated canadian pharmacies online canadian pharmacies online prescriptions canadian pharmacies
    canadian pharmacy uk delivery
    the canadian pharmacy
    prescription pricing
    mail order pharmacies
    canadian pharmacy
    walgreens pharmacy

  51. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    You stated it exceptionally well!
    http://canadianpharmacymim.com/
    pharmacy prescription global pharmacy canada reputable canadian mail order pharmacies trust pharmacy canada
    online drugstore
    canadianpharmacy
    online pharmacy
    drugs without prescription
    canadian rx pharmacy online
    canadian pharmacy viagra brand

  52. Quentintag says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Nicely put. Kudos.
    https://nicktambone.com/
    pharmacies in canada online pharmacies canada online pharmacies no prescription canada pharmacy
    mexican pharmacy online medications
    buying drugs canada
    canadian pharmacies online prescriptions
    buy drugs online
    no prescription pharmacies
    canada pharmacies without script

Leave a Reply

Your email address will not be published. Required fields are marked *