Calculating mode with interger arrays.

I'm having some trouble implementing code to search for modes inside of an interger array. The array is of values from 0 to 100.
public static String modeFinder(int[] input)
String output = "";
int[] modes = new int[input.length/2];
int[] occurances = new int[input.length/2];
int counter = 0;
int counter2 = 0;
for (int i = 0; i < input.length; i++)
int num1 = input;
for (int j = 0; j < input.length; j++)
if (input[i] == input[j])
counter++;
if (counter > 1)
modes[counter2] = num1;
occurances[counter2] = counter;
counter2++;
The last part is where i am having trouble. I esentially need to find the highest value in the occurances array and then check to see if there are multiple modes and then make a connection with the modes array of actual interger values that are a part of the mode. Thanks for any help.

Now you get to figure out how I did it....
public class Test {
  public static void main(String[] args) {
    int[] myInt = {1,2,3,4,5,6,7,6,5,4,3,2,1,2,3};
    int min=100, max=0;
    for (int x=0; x<myInt.length; x++) {
      if (myInt[x]>max) max=myInt[x];
      if (myInt[x]<min) min=myInt[x];
    System.out.println("min="+min+" max="+max);
    int[] cnts = new int[max-min+1];
    for (int x=0; x<myInt.length; x++) cnts[myInt[x]-min]++;
    int maxCnt = -1;
    for (int x=0; x<cnts.length; x++) if (cnts[x]>maxCnt) maxCnt = cnts[x];
    for (int x=0; x<cnts.length; x++) if (cnts[x]==maxCnt)  System.out.println("mode at "+(x+min));

Similar Messages

  • Finding Mode of an array of numbers.

    I'm having troubles with finding the mode of an array of numbers.
    When the mode is in the middle of the set of numbers, it works, but when it is at the end, it doesnt.
    For example..
    if i had the numbers ...
    2,3,3,4,5,6,6,6 in an array, it would tell me that the mode is 3.
    if i had the numbers...
    2,4,5,5,5,6 in an array, it would tell me that the mode is 5.
    So the first set of numbers, the mode is incorrect, but the second set of numbers is correct.
    The following is my code...
    public static int getMode(int[] list)
    int mode = 0;
    int elements = 0;
    int tempMode = list[0];
    int temp = 1;
    for(int x = 1; x < list.length; x++)
    if(list[x-1] == list[x])
    temp++;
    }else{
    if(temp > elements)
    System.out.println("entered");
    tempMode = list[x-1];
    elements = temp;
    temp = 1;
    }else{
    temp = 1;
    mode = tempMode;
    return mode;
    }

    You need to add another test at the end of the loop:
        public static int getMode(int[] list)
            int mode = 0;
            int elements = 0;
            int tempMode = list[0];
            int temp = 1;
            int x;
            for (x = 1; x < list.length; x++)
                if (list[x - 1] == list[x])
                    temp++;
                else
                    if (temp > elements)
                        tempMode = list[x - 1];
                        elements = temp;
                        temp = 1;
                    else
                        temp = 1;
            if (temp > elements)
                tempMode = list[x - 1];
            mode = tempMode;
            return mode;

  • Can't get landscape mode with Qmix app on my iPod touch 4th generation....

    I cannot get my iPod touch to go into landscape mode either with the calculator or with my Persons Qmix software app. I have no problems on the iPhone or iPad, but it has all of a sudden stopped working. I tried rebooting the OS, a reset and the orientation lock is off on the unit...help?

    Well, it went into landscape mode and I used it with QMix several times, then all of a sudden it would not go into landscape mode for ANYTHING not just QMix and Ihave tried double tapping on the bottom and making sure the orientation lock was not on......any other ideas? Im thinking i may have to send it to Apple to get this resolved...

  • LIN Diagnostic mode with VI / C (DLL)

    Hello all,
    I'm trying to communicate with a DUT using LIN Diagnostic mode.
    I'm making use of the NI PCI-8516. 
    I had a look at the examples on the CD that came with the product.
    There are VI and VS C examples.
    With the VS examples, I saw that sending PDU packets with LIN isn't implemented.
    With Flexray, it is.
    I tried modifying the LIN VI examples to send PDU packets (see examples).
    Everything is set on PDU and I also modified the LDF for diagnostic mode.
    I tried to modify the Init LIN Frame array VI .
    After running, following exeption is given: 
    [IMG]http://i57.tinypic.com/2due6bn.png[/IMG]
    Someone experienced this error before?
    Is it even possible to use LIN diagnostic mode with a VI using NI XNET?
    Does anyone by chance ever created a driver (dll/ VS project) which can communicate over LIN diagnostic mode?
    Thanks in advance!!
    BR Jeroen
    Attachments:
    LIN Frame Input Output Same Port_Test_Diag_Mode.vi ‏39 KB
    NI-XNET Example subVI - Initialize LIN Frame Array_Diag.vi ‏26 KB
    NIXNET_exampleLDF_dia.txt ‏3 KB

    btw the Automotive Diagnostic Command Set offers LIN Diagnostics at a high level
    so may check if it offers what you are looking for as already build in feature:
    http://sine.ni.com/nips/cds/view/p/lang/en/nid/203​554

  • Programatically knowing Calculation mode of Item

    Hello!
    Is it possible in Oracle Forms 10.1.2.0.2 to get values of the "Calculation Mode", "Summarized Item" etc properties?
    Thank you

    I'm sorry, I'll try to explain
    I have PL/SQL Library with
    procedure Show_Item(in_blockItem_tx varchar2) is
    it_id Item;
    begin
         it_id := Find_Item(in_blockItem_tx);
    code;
    Set_Item_Property(it_id, VISIBLE, PROPERTY_TRUE);
    Set_Item_Property(it_id, INSERT_ALLOWED, PROPERTY_TRUE);
    Set_Item_Property(it_id, UPDATE_ALLOWED, PROPERTY_TRUE);
    code;
    end;
    if in_blockItem_tx is Calculated field I get the error...
    right now I hardcoded filed names
    if in_blockItem_tx not in ('FORECONCILEBP.INIT_CBR_TOTAL', '***') then
    Set_Item_Property(it_id, INSERT_ALLOWED, PROPERTY_TRUE);
    Set_Item_Property(it_id, UPDATE_ALLOWED, PROPERTY_TRUE);
    end if;
    Is it possible to understand (runtime) if "Calculation Mode" property is set to 'Summary' or 'Formula'?
    Thank you

  • How Do You Populate A Spark List Control With An Array?

    Hello, all,
    Sorry to come accross so frustrated, but how in the name of God do you populate a Spark list control with the data in an array?  You used to be able to do this with the mx:List control, but the guys developing Flex just had to make things more difficult than they need to be!  I am more of a code purist and prefer doing things the way they have been done for decades, but apparently nothing can ever stay simple!
    I simply want to populate a list control with an array and this shouldn't be rocket science!  I found out that I must use a "collection" element, so I decided that an arrayCollection would be best.  However, after searching Adobe's documentation about arrayCollections, I am lost in a black hole of data binding, extra lines of code just to add a new element, the need to sort it, etc...!
    Here is my code:
    var pendingArray:ArrayCollection = new ArrayCollection();
    for ( var i:int = 0 ; i < queue.length ; i++ )
         var item:UserQueueItem = queue[i] as UserQueueItem ;
         if ( item.status == UserQueueItem.STATUS_PENDING )
         pendingArray.addItem({label:item.descriptor.displayName,descriptor:item.descriptor});
    Here is the relevant MXML:
    <s:VGroup>
         <s:List id="knockingList" width="110" height="100"/>              
    </s:VGroup>
    I'm not getting any errors, but the list is not populating.
    I have seen several examples where the arrayCollection is declared and populated in MXML:
            <mx:ArrayCollection id="myAC">
                <!-- Use an fx:Array tag to associate an id with the array. -->
                <fx:Array id="myArray">
                    <fx:Object label="MI" data="Lansing"/>
                    <fx:Object label="MO" data="Jefferson City"/>
                    <fx:Object label="MA" data="Boston"/>
                    etc...
               </fx:Array>
            </mx:ArrayCollection>
    That may be fine for an example, but I think this is a rare situation.  Most of the time I would image that the arrayCollection would be created and populated on the fly in ActionScript!  How can I do this?
    Thanks in advance for any help or advice anyone can give!
    Matt

    In your post it seemed like you were trying to take care of many considerations at once: optimization, design, architecture.  I would suggest you get something up and running and then worry about everything else.
    If I use data binding, then I will probably have to declare the  arrayCollection as a global variable and then I'll have to write 100 or  so extra lines of code to addItem(), removeItem(), sort(), etc...  It  just seems like too much overhead.
    I believe you may have some misconceptions about databinding in general.  You won't have to make it a global variable and you certainly won't need an extra 100 lines of code.  If you did this forum would be a very , very quiet place.
    I don't want to use data binding because the original array is refreshed  often and there is one function called by an event that re-declares the  arrayCollection each time, populates it with the array, and then sets  it as the list's dataprovider.
    That is the beauty of the ArrayCollection, it can handle the updates to its source Array. I don't know if you need to redeclare the ArrayCollection, resetting the source to the new Array allows everyone involved to keep their references so you don't have to worry about any "spooky" stuff going on.

  • E72 problem to activate silent mode with 031.023

    now it is very difficult to activate silent mode with the ctrl key !

    I think this is not a bug, but a fix. In the previous FW it was TOO easy to switch to Silent mode and that would happen quite often by mistake (at least to me).
    So I think that Nokia corrected this problem, but did not communicate properly with their customers....
    2110i, 6150, 6210, 6310i, 6670, 9300, 9300i, E90, E72, HTC Touch Pro2, Samsung Galaxy S, Samsung Galaxy S II

  • Help with parallel arrays of different data types

    Hello all, I am having an issue with parallel arrays. My program requires me to read information from a text file into 4 parallel arrays (2 String and 2 double). My text file needs to look something like this:
    John Johnson
    0000004738294961
    502.67
    1000.000
    Jane Smith
    0000005296847913
    284.51
    1000.000
    ...and so on
    Where the first thing is the name (obviously), an account number, the balance in the account, and the credit limit. I just cant figure out how to read everything into the arrays. We havent learned anything too heavy, and this seems a little too advanced for my class, but I guess we will manage. Any help will be appreciated. Thanks guys.
    Casey

    Man this is a dumb homework assignment. The requirements scream out for a class along the lines of
    public class Account{
      private String name, number;
      private double balance,creditlimit;
       // more code here
    }and then to use a List of Account objects.
    Anyway what's your actual problem. There's nothing very hard about it. A loop. So....
    You should consider posting (formatted) code showing what you have done and where exactly you are stuck.

  • Is there a way to use the iMac's display mode with a Mac mini with out logging in first on the Mac mini

    Is there a way to use the iMac's display mode with a Mac mini with out logging in first on the Mac mini (late2014)
    im currently useing my Mac mini as a portable computer, I take it to the university and use the iMacs there as a monitor but before I can do that I have to log in to my Mac mini first which means doing it blind
    is there a way to put the IMacs into display mode with out logging into my Mac mini first
    or is there a portable monitor that I can use that will not require me to login first

    This
    Target Display Mode: Frequently Asked Questions (FAQ) - Apple Support
    says:
    How do I enable TDM?
    Make sure both computers are turned on and awake. 
    Connect a male-to-male Mini DisplayPort or ThunderBolt cable to each computer.
    Press Command-F2 on the keyboard of the iMac being used as a display to enable TDM.
    Note: In Keyboard System Preferences, if the checkbox is enabled for "Use all F1, F2, etc. keys as standard functions keys," the key combination changes to Command-Fn-F2.
    How do I exit TDM?
    To leave TDM, press Command-F2 on the keyboard of the iMac that is in TDM. You can also exit TDM if you shutdown or sleep either computer or detach the cable.
    Can I use a third-party keyboard or older Apple keyboard to enable TDM?
    Some older Apple keyboards and keyboards not made by Apple may not allow Command-F2 to toggle display modes. You should use an aluminum wired or wireless Apple keyboard to toggle TDM on and

  • Firefox plug in container has stopped working, even in safe mode with plug ins disabled

    My firefox keeps crashing every 5 - 10 minutes. Sometimes I get a windows error message saying "firefox plugin container stopped working", but most times I don't. These are the actions I've taken so far, with no effect:
    1. Updated all my plug-ins
    2. Run firefox in safe mode with plug-ins disabled
    3. Uninstalled and reinstalled firefox
    4. Run an AVG scan which turned up nothing
    Can anyone offer advice on how to fix this (very annoying) problem?
    I've had to write this in IE because firefox wouldn't stay open long enough for me to copy and paste it into the text box.

    Try creating a new Profile by following the steps from [[Managing Profiles]] [[Troubleshooting extensions and themes]] and also [[The Adobe Flash plugin has crashed]]

  • How can I get to DFU mode with a broken power button?

    How can I get to DFU mode with a broken power button?

    aarons84 wrote:
    This is bad, but i tried jailbraking my iphone
    You may as well stop there. We can't help you.

  • Can't log in with valid password, can't boot from disk, can't access disk utility, in single user mode can't reset password as appears locked in caps mode with '?' for forward slash, can anyone help?

    Can't log in with valid password, can't boot from disk, can't access disk utility, in single user mode can't reset password as appears locked in caps mode with '?' for forward slash, can anyone help?

    Which keyboard layout you were using? German, French ... I suppose your layout is reset to the default: US and you are unable to find the "?" or "/" ...
    Please have a look into the keyboard viewer, to see how the layout of your keyboard is actually.
    marek

  • Firefox 29 When I right click to open in a new tab, the tab will open but it will be a blank page. Tried Firefox Safe Mode & with Ad On Disabled Nothing

    When I right click to open in new tab, the new tab will open but the page is blank. I have tried it in Firefox Safe Mode & with Add Ons Disabled, still doesn't work.

    Hi UKBlue,
    Is your new tab page set to about:blank? You can change this from the about:config page or you can restore defaults by resetting Firefox.
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information. <br>
    '''Note''': ''This will cause you to lose any Extensions and some Preferences.''
    *Open websites will not be saved in Firefox versions lower than 25.
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Hierarchy on HANA Calculation View with Optional Input Parameters Fails

    Hi,
    Has anyone succeeded in building a hierarchy on top of a calculation view with optional input parameters, where an input parameter is not filled?
    The original requirement came from the wish to create a parent child hierarchy on a calculation view that was copied into the customer space from a HANA Live Financial Statement query view, but I have found the following when creating a simple level hierarchy on a calculation view that consumes one table. The Calculation View has one Input Parameter where the 'mandatory' box is unchecked.
    Calculation view reads ECC table FAGLFLEXT
    Simple level based hierarchy on fields PRCTR, RACCT and SEGMENT
    Input parameter is used as a filter for PRCTR with logic ("EMPTY" = '$$P_PROFITCTR$$' or "PRCTR" = '$$P_PROFITCTR$$')
    When I run the view I see the following behaviour in HANA Studio and Analysis for Excel
    Before building the hierarchy I could run the view with or without the Input Parameter
    After building the hierarchy I can run the view with the Input Parameter filled, but it fails when the Input Parameter is not filled.
    Error message is "error: search table error:  [2426] missing placeholder; missing value for mandatory parameter P_PROFITCTR"
    P_PROFITCTR is not a mandatory parameter, but the selection for the hierarchy view thinks it should be. I don't find any notes around this issue, so I don't think it's version related, however the version I have used for this test is 1.00.70.
    It's a shame we can't currently build the hierarchy as the parent child relationship is provided in HANA Live view NewGLFinancialStatementQuery.
    Thanks,
    Ken

    Hi Ken,
    We have been facing similar issue. We have even tried to set default value and as optional parameter. View still fails to create hierarchy (we are not using HANA live). As mentioned on page 97 of HANA modelling guide input parameter is mandatory from engine point of view. Hierarchy is generated as column view during the initial activation of calculation view and therefore expect a value by caller.
    This seems to be a product error. Some one from HANA development team should explain this issue in detail. I would expect someone like Thomas Jung reply to us.
    At the moment, we cant use input parameter for date prompt which gives us calendar popup feature for date selection. Hierarchies just don't work with input parameter. We are missing something.
    Regards
    Angad

  • Error when opening XLSX file with Excel 2003 SP3, file does open but in read only mode with temporary name

    I am using Excel 2003 SP3 and have the Office 2007 compatibility pack installed.  When I open Office 2007 formatted Excel files (XSLX) directly in Windows Explorer, I receive the following error if I do not have Excel already opened:
    "Windows cannot find '<path to file>'.  Make sure you typed the name correctly, and then try again.  To search for a file, click the Start button, and then click Search."
    Even though I receive the error, the file does open; however, it opens in Read Only mode with a name such as "Xl0000024.xls".  The number seems to increment up each time it happens.
    Now here is the strange part.  If I have Excel already open and try to open the file in Windows Explorer, the file opens fine in Modify mode with no error and with the correct file name.
    I Googled the error I was getting and found KB211494.  It says I should uncheck the box in Options on the General tab that says "Ignore other applications", but this box is already unchecked in my case.  Any other ideas?  This is
    really frustrating as a small percentage of our company has upgraded to Office 2007 with the rest still on Office 2003.

    This may be a file association problem.  To solve that:
    In Windows 7:
    1. Right-click the file,
    2. Select "Open With" 
    select [Your Program Here]
    3. Check always use this program. 
    In Windows XP:
    1. Locate the file as you have described above
    2. Right click the file
    3. Select Open with from the pop-up menu
    4. Click Choose default program…
    5. Select Excel in the Recommended Programs box
    6. Check Always use the selected program to open this kind of file
    7. Click on OK.
    1.  Make Excel not available from Office 2007 listed under Programs and Features in Control Panel.
    2. Take a registry backup using the steps given here
    3. In the registry editor window expand HKEY_CLASSES_ROOT and navigate to .xls right and delete it.
    4. Exit Registry Editor
    5. Undo Step 1 to make Excel available.
    6.  Restart the computer and verify it the issue is fixed.
    If this answer solves your problem, please check Mark as Answered. If this answer helps, please click the Vote as Helpful button. Cheers, Shane Devenshire

Maybe you are looking for

  • How to Disable caching of all SSL pages?

    May anyone can help me, how to Disable caching of all SSL pages in an web application? Thanks in advance. Balamurugan.K

  • Hi,can someone teach me how to use save command in netbeans 6.7 ME

    hi,can anyone teach me how to save every information i stored on a form1,like datefield, textfield,and saving it in another form2, is there a code for that?, and showing in form2 the saved information,is it possible? and how in visualMidlet. tnx

  • How many seconds will query opens up

    Hello, can anyone tell us how much time will it take for a query to open in Bex analyzer and Browser? I know there are other dependencies like selection parameters, query design etc. calculations, formulas, structures etc.. But is there any bench mar

  • How to make my mac compatible w/ cs5

    i just upgraded my mac os x to snowleopard (version 10.6.3), thinking that'd allow me to use CS5 design standard, but it still doesn't meet system requirements for indesign. can i upgrade w/out having to buy a new computer and if so, what needs upgra

  • Object type RSDS not supported in BAPI source system

    Hi We have a problem when trying to create Data Source in NW2004s with 3rd party tool 'Ascential Datastage' as source system.The error message is "DataSource XXX (DS-DEV): Object type RSDS not supported in BAPI source system". Is there any note or pa