Two largest numbers

Hi All,
I am a beginner and need help. I am writing a small program that displays the two largest numbers from a group of 10 numbers. I can have display one number but do not know how to display the second largest number.
Any help would be appreciated.
Here is the code:
----- public class MyClass1 {
public static void main( String args[]) {
int number, counter=1, largest=0, largest2=0;
String input, output;
while ( counter <= 10 )
input = JOptionPane.showInputDialog(
"Enter an Integer from 1 to 10:");
number = Integer.parseInt( input);
largest = Math.max( number, largest);
counter = counter + 1;
JOptionPane.showMessageDialog( null,
"The largest number is" + largest);
System.exit(0);
Thanks
Oamen

If you wanted to keep the format of what you're going, and not get into Collections (assumedly, you're fairly new to Java), then you could implement something like..
public class MyClass1
int first_largest = 0;
int second_largest = 0;
public static void main(String args[])
  for(int i=0; i < 10; i++)
     input = JOptionPane.showInputDialog(
     "Enter an Integer from 1 to 10:");
     number = Integer.parseInt( input);
     //i'm not going to write everything for you
     //but here, you could do some tests to determine
     //if "number" is bigger than either of your two
     //numbers, and if so, rearrange them accordingly
     //You have access to first_largest and second_largest
     //since they are both global variables.
  System.out.println("Largest: "+first_largest);
  System.out.println("Second largest: "+second_largest);
}

Similar Messages

  • I am wanting to exactly match two ID numbers from two differing worksheets within one work book. Once matched I am wanting to retrieve a row value from the second worksheet into the first. Any help much appreciated.

    I am wanting to exactly match two ID numbers from two worksheets within the one work book. ID numbers are non linear. Once exactly matched I wish to retrieve a corresponding row value from worksheet two and have it appear in worksheet one against the correct ID number. I have been looking at IF, VLOOKUP, and MATCH functions and suspect that what I want to do requires a combination of two or more. Any help will be greatly appreciated.
    regards Vaughanh

    Vaughan,
    Data A:D is all cells start at column A thru column D.
    There is built-in help using the menu item "View > Show Function Browser"  in the search field (top right) you can enter vlookup and you will see the detailed description.
    From this we see:
    VLOOKUP
    (search-for, columns-range, return-column, close-match)
    search-for:  The value to find. search-value can contain any value type.
    columns-range:  A range of cells. range is a reference to a single range of cells, which may contain values of any type.
    return-column:  A number that specifies the relative column number of the cell from which to return the value. return-column is a number value. The leftmost column in the range is column 1.
    close-match:  An optional value that determines whether an exact match is required.
    close match (TRUE, 1, or omitted):  If there’s no exact match, select the column with the largest top-row value that is less than the search value. Wildcards can’t be used in search-for.
    exact match (FALSE or 0):  If there’s no exact match, return an error. Wildcards can be used in search-for.
    So... the 2,0 means return the value form the same row as the lookup value but from the 2nd column of the range.  3, 0 means from the 3rd column.  the ", 0" means exact match

  • I have two phone numbers in facetime want to remove one

    i have two phone numbers on facetime want to remove one.

    Settings>facetime> remove the number under the "You can be reached for video calls at" Option.

  • Is it possible to use a single iPhone with two contact numbers via dual sim or an app?

    Is it possible to use a single iPhone with two contact numbers via dual sim or an app?
    This would be a useful feature for personal and company numbers but using one mobile, rather than carrying two devices or diverting calls.

    Then go ahead and try it.  You'll find it's probably a load of crap.
    You want 2 numbers, then use Google Voice or TalkaTone
    Those are US based only Apps or numbers so no good. I won't be wasting money by just trying something either, especially because using a dual sim would mean purchasing another sim card on either pay as you go or monthly contact.

  • My assistant and I are using two Lightrooms (i.e. two serial numbers) and need to share between our two computers. I provide originals to her onto a flash drive. She tags them and returns them to me. I then copy the photos from her flash drive onto my com

    My assistant and I are using two Lightrooms (i.e. two serial numbers) and need to share between our two computers. I provide originals to her onto a flash drive. She tags them and returns them to me. I then copy the photos from her flash drive onto my computer and load them in my LR. The photos appear but witthout any editing or tagging. We need to be able to have her working on the photos on her computer with her copy of LR and me on my computer with my version of LR being able to access what is already tagged and given back to me. This seems hard. We need advice on if it is at all possible to have two computers simultaneously working on LR . I bought her her own version because I was told at the time of purchasing that that was the only way to share. Please advise urgently! Thanks.

    Sounds like your assistant isn't instructing Lightroom to write the tagging and editing to the files themselves, so wehn the files return to you, they don't have editing and tagging information. She need to select the photos in Lightroom and then Ctrl-S (Cmd-S on Mac). Or alternatively turn on the option to autmoatically write this information to the files.
    If you are using RAW photos, then this information will be written to a sidecar XMP file, and your assistant must provide you with the sidecar file. If these photos are not RAW photos, then the information is written directly into the photo file itself.
    Lightroom wasn't designed to be a multi-user program, and so it is truly not possible to have two people working on the same catalog at once. The way you are doing things, as modified above, is probably the way to go.
    As an alternative, you can transfer (portions of) catalogs as well as photos back and forth and then all of these issues disappear, but a catalog might be rather large for a flash drive (or maybe not, it depends)

  • My Nokia Lumia 800 has two IMEI numbers. What?!

    Hi Everyone,
    Purchased a Lumia 800 (white) from Nokia Store here in Bangalore, India on August 2012. The phone was working fine till August 2013 when camera stopped working. Took the phone to Nokia Care. Warranty checked out fine and the camera module had to be replaced. Got call from Nokia Care three weeks later saying there has been IMEI mismatch as such warranty is now void. Reason- the phone has two IMEI numbers. What??
    And funny, Nokia's story was true. IMEI number written on the phone panel and phone box differed from internal hardware IMEI number (which can also be seen from Settings>About). They say this can only happen if the phone was serviced earlier and component changed. Well, this was my first time servicing the phone and when the phone is under warranty why will I give for servicing to a non-nokia centre?? This shocked me, I could not convince Nokia people so I just agreed to pay for the repair. Now, after 3 days, they call up and say- "Changed the camera module but it is still not working. Maybe your motherboard is damaged! you will be charged 80% of the phones price if you agree with repair". I am yet to give them the 'go ahead'.
    For no fault of mine I am going through so much!! Is it possible that Nokia sold me a device with two IMEI numbers?? Can anyone please tell me what to do?? Thanks.

    Nokia wouldn't have sold a device in that state. It's highly likely that the retailer is to blame for this one. They've probably sold you a refurbished or repaired set as new.
    If I was you I would go and speak to the retailer about this.

  • To enter two VAT numbers for one vendor in the same country

    Hello All,
    When we try to enter two VAT numbers for one vendor in the master record and belongs to the same country, the system is not allowing and gives the following message,
    "VAT reg.no. already exists for country BE"
    Message no. F2140
    Kkindly let me know the way to proceed further.
    Many thanks in advance.

    Hello,
    Go to OBA5 and switch off the message for online and batch entries.
    If the message is already not there in OBA5,
    Then go to OBMSG and switch off the same.
    Application Area F2
    Message No.140
    Regards,
    Ravi

  • When I upload files and correct in lightroom then I export to another named file I keep getting two duplicates. numbered 1 and 2. this never happened before

    When I upload files and correct in lightroom then I export to another named file I keep getting two duplicates. numbered 1 and 2. this never happened before

    When I first upload to lightroom I set up a file called new photos. When I correct them I export to a newly named file. But when I go to the newly named
    File on my harddrive there are duplicate files
    Stan

  • Two serial numbers requestet - but I only have one

    Hello, I bought a version of lightroom 5 today and downloaded it. Now I wanted to start the program and it asked for two serial numbers. The actually serial number was sent per Email but it also asked for an older serial number, but this is the first program I bougt and I do not have any other number. Does anyone has an idea. Sorry if my english isn't perfect. Greets Franzi

    you must have purchased an upgrade.  in that situation you will be prompted for the lr 5 serial number and then when the installer fails to find a qualifying product (eg, a previous lr version), you are prompted for the previous versions serial number.
    if you don't own a previous version, you purchased the wrong lr version (ie, an upgrade).  Return, cancel, or exchange an Adobe order

  • Two warehouse numbers in one plant

    Is it possible to have two warehouse numbers in one plant and how do i get this to work?Can the same users work in first and second warehouse?What are the things that i need to define searately in second warehouse number?What is the difference if i still have one warehouse number and split two warehouses in 2 different warehouse numbers?

    Is it possible to have two warehouse numbers in one plant and how do i get this to work?
    Sure, you just need to create another WhNum and assign it to the SLoc(s).
    Can the same users work in first and second warehouse?
    Yes, but you will be required to change their WM profile in LRFMD to make it work.
    What are the things that i need to define searately in second warehouse number?
    Not sure I understand the question correctly. You need to have all the WM settings for this warehouse number separate, although some values might be the same (print program, storage types, movement type config, etc.) but they need to be specified for the key of your new WhNum.
    What is the difference if i still have one warehouse number and split two warehouses in 2 different warehouse numbers?
    There are many differences... You will be able to make the movement types config different which is important if your process requirements are different.
    You will have two warehouse monitors RF monitors (LRF1/LRF2 t-code).
    You will be able to specify different internal SU number if you are using storage units.
    You will be able to have the same storage types in different WhNUms, e.g. you can have 001 in WH1 and 001 in WH2 too without conflict.
    Have different print programs, settings in mobile data entry etc.
    Well, there are many other differences. It would be good if you could specify which operations / processes are of interest so we could elaborate about the specific differences you are interested in.

  • How to divide two int numbers and get a fraction ?

    I am dividing two int numbers and the result should be a fraction but I am always getting a zero
    set @result= @num1/@num2  
    when num1=50 and num2=100

    I am dividing two int numbers and the result should be a fraction but I am always getting a zero
    set @result= @num1/@num2  
    You can either one of the values as a decimal or float type, or just multiply one of the values by 1.0.
    set @result= @num1/@num2*1.0
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Invoice output must be sent to two fax numbers

    Hi,
    My client needs to send the Invoice to two different fax numbers. Is this possible if we maintain two condition records with two different partner functions that have these two fax numbers?
    Any ideas will be appreciated...
    Thanks,
    Sree.

    check these links, I believ it was discussed here several times.
    Re: Smart form as a fax
    SAP Script to Fax a PO
    /people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp
    Sending Smartforms through Fax
    I meant you can either define 2 output types with different partners which have different numbers to send FAX OR which is more flexible I think - write some code in your print program for your output type which will either just fax your output (set device to TELEFAX and populate other tables to provide fiax number & so on...) or just grab your sapscript ouput and then fax it using code (something like CONVERT_OTF_AND_FAX function modlule).

  • Using imessage with two mobile numbers  on one iphone?

    hi is it possible to use two mobile numbers on imessage ,   with only one iphone?
    i have an old phone , and an iphone, but would like to be able to use receive imessages on the iphone  , using the two numbers,  is this possible?
    thanks

    no

  • How can I get two missing numbers on a iTunes card

    How can I get two missing numbers on a iTunes card

    "Get help",just below the form space where I entered the code. Once I clicked "Get Help", it added another line to the form where I could enter  THE NUMBER ON THE BOTTOM LEFT CORNER on the back of the card. I entered as much of the I scratch-off code I could read, along with the serial number.

  • How to get my two online numbers forwarding to two...

    i have two online numbers, in the same skype account. I want to get them forwarding to two different mobilephone number, how can i do this. pls reply ASAP
    THANKS

    Sueva wrote:
    i have two online numbers, in the same skype account. I want to get them forwarding to two different mobilephone number, how can i do this. pls reply ASAP
    THANKS
    You can't do that.  With the two numbers on the same Skype account, you can't set different destinations for forwarding calls on those numbers. 
    If you wanted to have separate call-forwarding settings for your Online Numbers, you would need to have each Online Number on its own Skype account.  This means that, for forwarding to telephones, you would need to purchase Skype Credit or a subscription for each of those accounts.
    Patrick
    Location/Ubicacion: Arizona USA
    Time Zone/Hora Local: UTC/GMT -7
    If this message has adequately addressed your issue, please click on the “Accept as Solution” button. If you found a post useful then please "Give Kudos" at the bottom of my post, so that this information can benefit others.
    Si esto mensaje le ha ayudado, por favor haga clic en "Aceptar como solución". Si encuentra un mensaje útil, por favor "Da Kudos" al final del mensaje, por lo que esta información puede beneficiar a otros.
    I am not a Skype employee. No soy un empleado de Skype.

Maybe you are looking for