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. ErnestoTably says:
    Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.

    Thanks a lot, Ample information.

    female pleasure viagra viagra and cialis expiry notice
    cheap viagra
    law suits against viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Info clearly applied!!

    viagra and ketoconazole interaction buy bradn viagra
    viagra generic
    stamina rx and viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Regards, Plenty of content!

    express-scripts viagra viagra prescription refills
    viagra for sale uk
    medication viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Thanks a lot. I appreciate it!

    viagra boy 2cialis levitra viagra vs vs
    buy viagra
    viagra and no perscription and us – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Wow loads of helpful tips.

    viagra light switch online sellers of viagra worldwide
    generic viagra 100mg
    thug viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Thanks a lot. Numerous information.

    viagra maximum dose viagra erection after orgasim
    generic viagra 100mg
    how much viagra can you take – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You actually reported it fantastically.

    jelq on viagra canada drugs viagra without prescription
    generic viagra 100mg
    how long do you take viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You made your stand extremely well!!

    viagra racial discrimination prostate cancer viagra
    cheap viagra
    comments on viva viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You’ve made your point extremely effectively!.

    viagra television commercial can you mix tramadol with viagra
    viagra generic
    viagra how to buy – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Many thanks, Useful information!

    find viagra free online search viagra alternative and woman
    viagra 100mg
    does viagra increase penis size – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put, Appreciate it.

    long term efffects of viagra generic viagra online cashiers check
    generic viagra
    viagra with prescription – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You actually suggested it wonderfully!

    order viagra without prescription viagra recreational use
    generic viagra 100mg
    radip release viagra tablets – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put, Cheers!

    viagra and eye problems lifting weights on viagra
    buy viagra
    viagra herbal – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Seriously plenty of fantastic tips!

    gag viagra coupons tinnitus viagra
    generic viagra online
    viagra joint problems – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You said it adequately.!

    can you take alcohol with viagra viagra max complaints
    viagra generic
    viagra vs cialis vs lavetra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You said that superbly!

    viagra savings coupon female viagra pharmaceutical
    buy generic viagra
    watch viagra tv ads – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Seriously lots of useful material.

    viagra canada pharmacy buy generic viagra si br
    viagra without a doctors prescription
    bug viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Truly a lot of amazing information.

    viagra vs nasal spray herbal uk viagra
    viagra 100mg
    how to make viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Cheers. An abundance of knowledge!

    for viagra rx canada viagra
    viagra 100mg
    viagra discount viagra prescription drugs – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Truly many of valuable info.

    maryland cialis tadalafil viagra trial viagra
    generic viagra
    can you have too much viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You actually explained it fantastically.

    cvs viagra xost which is stronger viagra or cialis
    viagra 100mg
    mens experience with viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Wow all kinds of beneficial info.

    cheap generic substitute viagra ultram viagra vioxx xenical
    viagra generic
    sites computer viagra pages edinburgh search – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Fantastic info. Appreciate it.

    inventor viagra charles linskaill find search viagra
    viagra for sale uk
    viagra pussy – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

  25. ErnestoTably 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.

    do generic viagra work yahoo chipmunks viagra song lyrics
    buy viagra online
    find viagra free charles linskaill – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Regards, Ample facts.

    viagra fast delivery le viagra
    generic viagra 100mg
    rezeptfrei viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You expressed this well!

    viagra non oral woman use viagra
    viagra pills
    how dow es viagra works – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Kudos, Plenty of content.

    online sellers of cialis and viagra the seven dwarfs and viagra
    viagra pills
    psa viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

  29. ErnestoTably 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 pretty well!.

    target viagra how old to take viagra
    viagra for sale uk
    viagra lahore – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Incredible many of beneficial tips!

    hugh hefners viagra supply bulgaria viagra
    viagra without a doctor prescription
    benign prostatic hyperplasia and viagra – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Amazing all kinds of excellent knowledge!

    can you buy viagra without prescripition eye damage from viagra
    viagra generic
    horny goat weed vs viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You explained that perfectly!

    atenolol and viagra best price for viagra
    viagra generic
    how to maximize viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put. Kudos.

    what is a viagra overdose need something better than viagra
    buy viagra online
    india generic viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Thanks. Ample forum posts.

    multiple orgasms and viagra men what happens with viagra and steroids
    buy viagra online
    are viagra and cialis the same – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Reliable facts. Kudos.

    viagra exposed colleagues viagra
    generic viagra online
    786 heart herbal mixing viagra 1132 – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You actually revealed it superbly.

    cost of viagra at walmart pharmacy viagra search edinburgh ago hours
    buy viagra online
    order viagra onlines – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put. Thanks.

    viagra corporate citizenship chemist no-risk viagra
    viagra without a doctors prescription
    generic softtabs viagra – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put. Appreciate it!

    viagra prices virginia walmart is mexican viagra real
    viagra pills
    does female viagra work – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Incredible tons of wonderful material!

    india viagra cialis vicodin whats the generic name for viagra
    viagra for women
    viagra online ohio – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put, Cheers.

    buy viagra online no prescription viagra in peru
    generic viagra 100mg
    generic cheap viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    With thanks. I enjoy this!

    making viagra funny viagra
    viagra without a doctors prescription
    viagra falls band south bend – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Wonderful forum posts. Thank you!

    penegra silagra generic viagra cumwithuscom vasotec and viagra interactions
    buy viagra online
    viagra alerts google charles linskaill reply – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Appreciate it, Lots of data.

    viagra online without prescription uk mdma viagra
    viagra 100mg
    cheapest price viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Nicely put. Kudos.

    viagra with out a perscription gp prescribing viagra
    generic viagra 100mg
    get viagra now – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Wonderful info, Thank you.

    call appointment doctor viagra buy viagra ups
    generic viagra 100mg
    stories of viagra – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Whoa all kinds of terrific material!

    2004 viagra nascar car viagra 100mg in croatia
    viagra for sale uk
    show how viagra works – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Superb info. Thank you.

    free viagra sample viagra sample cheapest generic price viagra
    viagra 100mg
    2003 daily feb online statistics viagra – https://genericviagrarcp.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You actually reported that terrifically.

    how does viagra affect blood pressure viagra and ketoconazole interaction
    generic viagra 100mg
    connecticut meltabs generic viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Thanks, Very good stuff!

    viagra vs and prozac viagra cause peyronie’s disease
    cheap viagra
    free viagra in the uk – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

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

    Superb facts. With thanks!

    cheapest viagra online in the uk can viagra cause restless leg syndrome
    viagra generic
    silagra generic viagra cumwithuscom – https://genericviagrantx.com

    Keithcet
    Richardhug
    ErnestoTably

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

    You suggested that superbly!

    babys lungs and viagra which is better cialis soft or viagra
    viagra online
    naming viagra – https://genericviagramsl.com

    Keithcet
    Richardhug
    ErnestoTably

Leave a Reply

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