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

    Appreciate it, A lot of knowledge!

    viagra liquid publicidad viagra marketing
    generic viagra 100mg
    delayed ejaculation and viagra – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Fantastic content. Cheers!

    active ingredient of viagra buy levitra online viagra
    viagra generic
    coffin viagra – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You actually explained that wonderfully.

    how hard does viagra make you woman takes viagra
    buy generic viagra
    viagra cautions – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Very good facts. Thanks!

    diabetes and viagra edinburgh uk viagra pages href computer
    generic viagra online
    buy viagra with paypal – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Good write ups. Regards!

    chasity and viagra viagra onlone
    buy viagra
    professional viagra pills – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Fine advice. Kudos.

    norvasc viagra and buy generic viagra without prescription
    viagra generic
    nitric oxide and viagra cgmp – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You actually reported it very well.

    viagra without priscription viagra fda approval
    viagra generic
    viagra brands – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks a lot. Fantastic information!

    where can i get viagra viagra money laundering
    buy generic viagra
    rlc nevada viagra – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You made your stand pretty well!!

    x cite herbal viagra for woman genic viagra
    buy generic viagra
    best deals on cialis viagra – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Superb knowledge. Thanks!

    viagra and alcohol viagra side effects dangers
    generic viagra
    is viagra addictive – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

  12. LarryWag 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 this.

    viagra out of date viagra discussion board
    generic viagra
    why do you take viagra – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Amazing advice. Appreciate it!

    viagra cialis brain tumor viagra lung problems
    viagra generic
    using viagra a second time – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Wonderful info. Kudos.

    viagra substitute caribbean cruises 100mg viagra
    generic viagra 100mg
    free 6 viagra – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Amazing plenty of awesome material!

    v ritable viagra how to remove viagra official site
    viagra without a doctors prescription
    viagra norco – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Wonderful postings, With thanks!

    what heart condition uses viagra niagra to viagra
    generic viagra
    common spice viagra – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Nicely put. With thanks!

    viagra overdose murphey viagra
    viagra without a doctors prescription
    does viagra really work – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

  18. LarryWag 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 pretty nicely.!

    apcalis versus viagra find sites computer shop viagra search
    viagra without a doctors prescription
    viagra and milwaukee public schools – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Great postings, Thank you.

    does watermelon act like viagra viagra flomax
    viagra pills
    viagra rogain online sales – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Kudos! Excellent information.

    second best to viagra viagra 1
    buy generic viagra
    viva viagra commercial – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Kudos, A lot of postings!

    g postmessage viagra smiley reply what do viagra look like
    buy viagra online
    myocarditis viagra – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Nicely put, Appreciate it.

    side effects of warfarin and viagra when do you need viagra
    viagra 100mg
    natural viagra substitute – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

  23. LarryWag 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 data!

    viagra and sex pleasure viagra free viagra find charles edinburgh
    buy viagra
    viagra headquarters in toronto canada – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Valuable material. With thanks!

    viagra generic super active viagra and tv commercial
    viagra without a doctor prescription
    stop viagra spam emails – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thank you. Quite a lot of content.

    viagra substitutes over the counter cost of viagra in canada
    cheap viagra
    europe online sale viagra – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

  26. LarryWag 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.

    viagra best price sildenafil viagra contraindications
    generic viagra online
    international shipping order viagra – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Great data, Many thanks.

    what insurance companies cover viagra affordable viagra
    generic viagra 100mg
    what does uing viagra do – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    This is nicely said. .

    contact viagra large viagra dicks
    viagra without a doctors prescription
    sites computer viagra edinburgh find report – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks a lot, Plenty of tips!

    viagra 100mg price horseracing and italy and viagra
    viagra 100mg
    viva viagra theme song – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Seriously a good deal of fantastic info.

    viagra fix-a-flat chimp viagra
    generic viagra 100mg
    viagra party drug – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

  31. LarryWag 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.!

    metoprolol and viagra sale of viagra in uk
    buy viagra
    viagra on line uk – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks! Ample data!

    lavitra vs viagra charles linskaill find viagra free
    generic viagra 100mg
    viagra online issues – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Kudos. I like it.

    female viagra blog research cost of viagra
    viagra pills
    viagra stroke – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Many thanks. Valuable information.

    buy viagra on the internet viagra confidential fast prescriptions online
    viagra without a doctors prescription
    order viagra online a href iframe – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Appreciate it! A good amount of advice!

    will viagra work without stimulation how is viagra used for women
    buy viagra online
    viagra cut pills in half – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

  36. LarryWag 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 material!

    the little red pill like viagra janet smith viagra
    generic viagra 100mg
    viagra on the net – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Wow many of superb data.

    top 10 genuine viagra sites buy taladafil viagra
    generic viagra online
    cheap authentic viagra – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Information nicely regarded!.

    how to help viagra work better viagra switch plates
    buy viagra online
    money online order save viagra – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks. A lot of information!

    viagra and hypertension viagra propecia cialias
    viagra without a doctor prescription
    lowest viagra price at online pharmacy – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Wow tons of amazing material!

    can caverject be used with viagra india drugs viagra
    viagra online
    viagra dirty – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You actually explained it terrifically!

    women sex viagra viagra quick tab
    viagra pills
    soft tabs generic viagra – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

  42. LarryWag 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!

    viagra freesamples cost comparison for viagra
    generic viagra online
    when viagra dosent work – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    With thanks, I value it.

    viagra 36 hour generic viagra does it work
    buy viagra
    viagra on sale in france – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Awesome info. Kudos.

    com viagra viagra test
    generic viagra online
    viagra and cialis expiry notice – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You actually stated this very well.

    viagra falls 2 viagra losing effectiveness
    viagra online
    buy cheap viagra online now uk – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You actually stated this exceptionally well!

    wedding viagra viagra brands
    buy generic viagra
    generic viagra no prescriptio – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    You said this effectively.

    viagra doctors viagra nasal
    generic viagra 100mg
    viagra email sign up – https://genericviagrantx.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks! I appreciate it!

    funny names for viagra cheap viagra ads
    viagra for women
    does viagra have a shelf life – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Perfectly voiced of course! .

    mixing zanidip and viagra does health care cover viagra
    viagra generic
    viagra boring edinburgh pages spam boring – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks. Ample posts!

    how do i use viagra what does viagra look like
    cheap viagra
    viagra no longer works – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Position well considered..

    kamagra suhagra generic viagra viagra controlled drug
    generic viagra 100mg
    medication on line viagra – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Awesome material. Appreciate it.

    buy viagra online canada viagra news edinburgh cfm moo tid
    viagra pills
    viagra 125 mg – https://genericviagramsl.com

    GeraldBon
    Dwaynephync
    KevinPak

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

    Thanks, I like this!

    viagra half dose or full strength canada drugs viagra without prescription
    buy generic viagra
    how does viagra help pe – https://genericviagrarcp.com

    GeraldBon
    Dwaynephync
    KevinPak

Leave a Reply

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