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

    Cheers! I enjoy this.

    samples of viagra viagra testimonils
    generic viagra 100mg
    canyon lodge viagra commercial – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Perfectly expressed truly! !

    query viagra new viagra commerical august 2010
    viagra pills
    watermalon viagra – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    With thanks, Great information!

    online apotheke viagra oragel viagra sex
    viagra without a doctor prescription
    viagra 25mg – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Regards, Excellent stuff!

    herbal viagra in stores active ingredient in viagra natural
    generic viagra 100mg
    meltabs generic viagra – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Thank you, A good amount of write ups.

    does viagra have an expiration date viagra without prescription au
    generic viagra
    side effects to taking viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Whoa all kinds of useful tips!

    viagra young men generic viagra in united states
    generic viagra
    get free viagra – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Amazing stuff. Regards!

    low blood pressure taking viagra viagra order mail
    generic viagra
    viagra liquid – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You definitely made your point.

    stories viagra porn rapid release viagra tablets
    viagra without a doctors prescription
    edinburgh uk viagra tid news moo – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Thanks a lot, I enjoy this!

    what is a alternative to viagra commercial viagra
    buy generic viagra
    how will viagra feel – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Kudos! I appreciate it!

    cvs pharmacy viagra cost ebay bidding buy viagra
    viagra for women
    buy cheap viagra 32 – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You expressed it wonderfully!

    supplements that replaces viagra viagra great for group sex
    generic viagra online
    viagra effects on healthy males – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Nicely put, Appreciate it.

    jual viagra kl mobic viagra
    generic viagra
    usps delivery viagra – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You actually suggested this perfectly!

    top 5 viagra what is the structure of viagra
    viagra 100mg
    interaction of clonidine with viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Excellent stuff. Thanks a lot!

    medical journals viagra viagra within 24 hours
    viagra for sale uk
    does viagra really work – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Fine material. Kudos.

    achat viagra france watermellon rind viagra
    buy generic viagra
    viagra delivered on saturday by fedex – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Regards. Awesome stuff!

    recreational use of viagra safe online viagra
    viagra for sale uk
    natural herbal alternatives to viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Great stuff. Cheers.

    instructions for viagra interazione tra viagra e eutirox
    viagra pills
    viagra erektile dysfunktion diagnostik – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Nicely put, Thank you!

    generic viagra generic cialis pills free trial over the counter viagra
    generic viagra online
    free sites computer search viagra buy – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You actually stated this superbly.

    generic viagra differences why am i getting viagra email
    viagra for women
    levitracialis levitra viagra vs vs – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You explained this superbly!

    491 viagra heart 708 online viagra purchasing
    viagra without a doctors prescription
    oysters spiked viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You said it perfectly..

    interactions of different medications with viagra online viagra quality
    generic viagra 100mg
    does generic viagra work – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Beneficial facts. Cheers!

    viagra pharmacy sales londom viagra model
    generic viagra online
    buying viagra online legal – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Superb advice. Cheers.

    viagra tongue viagra and cialis drugs
    buy viagra
    re viagra cialis levitra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Incredible all kinds of useful data.

    refractory period viagra viagra and nito glycerin
    viagra online
    aching legs following viagra use – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Many thanks, Valuable stuff!

    viagra delivered on saturday by fedex viagra photophobia
    viagra for sale uk
    viagra real name – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Cheers. Loads of material.

    viagra a viagra 100mg substitute
    generic viagra online
    viagra vs prevacid – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    This is nicely put. !

    max viagra dose viagra kalnagra kamagra
    generic viagra 100mg
    best prices on viagra in drugstores – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Thank you, Great information!

    max viagra dose viagra and sex pleasure
    viagra online
    viagra did not work – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Seriously quite a lot of very good info.

    cat ate viagra recommended viagra dose
    viagra without a doctor prescription
    instructions for taking viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    With thanks! I like this!

    q buy viagra can i buy uae viagra
    generic viagra 100mg
    viagra meltaways – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Thanks! Quite a lot of postings!

    viagra falls psych pineapple spotting viagra for treatment of pulmonary hypertension
    viagra for women
    free older viagra movies – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    With thanks! Ample information.

    free viagra information viagra scientific name
    cheap viagra
    cheap kamagra generic viagra videos – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Reliable posts. Many thanks!

    viagra use in females viagra side effecs
    cheap viagra
    l-arginine comparable to viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Amazing advice. Thanks a lot.

    pills viagra canada viagra tylenol
    generic viagra online
    australia viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Whoa a lot of useful advice.

    viagra viagra find edinburgh pages search viagra enzyte combo
    generic viagra 100mg
    find viagra free computer sites – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Superb information. Many thanks!

    viagra generic low price viagra serendipity inventor
    viagra generic
    cialis levitra link pharmacies com viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Point certainly taken..

    levitracialis comparison levitra viagra pages edinburgh search viagra charles
    generic viagra 100mg
    can viagra lower your bp – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Amazing material. Many thanks.

    buy viagra in amsterdam viagra for less
    generic viagra
    viagra 50 mg quick dissolve – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Incredible all kinds of superb tips!

    viagra title object viagra related deaths
    viagra pills
    bisoprolol fumerate and viagra – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Whoa many of useful knowledge.

    importing singapore viagra everyday viagra
    buy viagra online
    legal female viagra alike – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Kudos. Very good stuff!

    free viagra hotline viagra and levitra
    viagra for sale uk
    paxil viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Lovely content, Appreciate it.

    viagra without prescription canada after effects of viagra
    viagra without a doctor prescription
    synthesis of viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You mentioned it terrifically.

    viagra when to take it viagra dosage best taken when
    generic viagra
    does unitedhealthcare pay for viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Whoa loads of beneficial facts.

    generic viagra pay with online check viagra permanent side effects
    cheap viagra
    viagra and seizures – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Truly many of excellent data.

    buy chinese herbal viagra photo effective viagra
    viagra 100mg
    buy cheap cialis generic levitra viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

  47. Andrewnon 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.

    2003 cialis levitra market sales viagra viagra permanent side effects
    buy generic viagra
    real viagra online – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Great facts. Cheers.

    enhancing the viagra experience viagra as a diet pill
    viagra 100mg
    buy discreet medical viagra drugs cheating – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Thanks. Great information!

    viagra in holland naproxen with viagra
    buy viagra
    where is viagra manufactured – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You have made your stand very nicely.!

    viagra active ingrediaent levitra viagra v cialis
    cheap viagra
    viagra 0r cialis – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Thank you! Loads of info.

    facts viagra tylenol nhs viagra
    generic viagra online
    viagra beer – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You reported this wonderfully!

    viagra hard on next day online viagra
    buy viagra
    genaric viagra free – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Awesome write ups. Thanks a lot.

    viagra cialis herbal substitutes viagra discount online
    buy viagra online
    sub for viagra – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Superb posts. Kudos.

    viagra in cream viagra tadalafil research
    viagra without a doctor prescription
    generic viagra super active – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    You said it very well!

    meredith viagra viagra super ed trial pack
    generic viagra 100mg
    ribavirin and viagra in combination – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

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

    With thanks! A good amount of stuff!

    sublingual viagra preparation viagra find search edinburgh soft
    generic viagra 100mg
    viagra suppositories flush rush – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Amazing info, Appreciate it!

    canadian parmacy viagra 100mg high blood pressure vs viagra
    viagra online
    free viagra consultation – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Wonderful advice. Thank you.

    do boots sell viagra last longer viagra
    viagra for women
    viagra empty stomache – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Regards, I enjoy it.

    koliko vremena pre treba uzeti viagra viagra in the philippines
    buy viagra online
    how hard does viagra make you – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Many thanks. A lot of advice!

    indications for viagra treatment in women viagra for masturbation
    generic viagra 100mg
    drinking alcohol with viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Good info. Thank you.

    find charles linskaill search viagra wendi virtual viagra
    viagra for women
    texas viagra caverta generic – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Good material. With thanks!

    viagra discount sales silagra generic viagra silagra cumwithuscom
    generic viagra 100mg
    retail cost of viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Nicely put, Cheers.

    viagra us forums side effects of levitre viagra
    viagra pills
    men taking viagra pics – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Nicely put. Kudos.

    viagra reliabel testimonial viagra stroke
    cheap viagra
    maker of viagra – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

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

    Wow tons of excellent information.

    retin-a metrogel prevacid viagra viagra being ineffective over time
    buy viagra online
    name buy viagra text buy viagra – https://genericviagrarcp.com

    DavidBooge
    TerenceBum
    VictorNut

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

    This is nicely expressed. !

    slim 60 like viagra generic viagra companies
    viagra pills
    viagra europe affiliates – https://genericviagramsl.com

    DavidBooge
    TerenceBum
    VictorNut

  67. Andrewnon 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.

    how to boost your viagra viagra effects on women
    viagra online
    viagra paypall – https://genericviagrantx.com

    DavidBooge
    TerenceBum
    VictorNut

Leave a Reply

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