Fixed-sized array

Hi all, I am after a bit of help.
I have a fixed sized array of 11. Each position is a month.
I need a variable set to 0, and the system searches through the array and if the number is bigger than the current highest figure passes it to it. When it gets to the end it prints out the position of the highest figure. It has to be done using a for loop also.
Here is an example that I've been told is going along the right lines, although I know there are a few obvious mistakes, am I right in using the length() method?
int highest = 0;
for (int index = 0; index <= mancData.length; index++)
System.out.println(mancData [highest];)
Sorry that it's very long winded not the best of explaining things.
Thanks in advance.

public class Rainfall
    // Comment
    private double[] mancData;
     * Constructor that state the rainfall for each month.
    public Rainfall()
        mancData = new double[12];
     * Method to populate the Arraylist.
    public void populate()
        mancData[0] = 187.3;
        mancData[1] = 234.4;
        mancData[2] = 219.9;
        mancData[3] = 323.7;
        mancData[4] = 256.7;
        mancData[5] = 164.2;
        mancData[6] = 126.6;
        mancData[7] = 98.6;
        mancData[8] = 149.0;
        mancData[9] = 198.9;
        mancData[10] = 254.7;
        mancData[11] = 221.5;
}That's my code now, yeah sorry Array of size 12, not 11. :)
I need it to search through the array and at the end print out the position of the highest rainfall, which is position 3.

Similar Messages

  • A string into a fixed sized array.

    Hello;
    I am tryig to implement a method that consumes a string that is made up of possible integers (for example String s = "1 2 3 4 5"; ) and returns it as an array such that the returned array will be {1,2,3,4,5} with size 5. This means it has to paste each number character that is not empty as integer and put them to the array.
    How can I achieve this?
    cheers.
    Edited by: Odinn on Jan 9, 2009 6:26 AM

    Hm ... I'm not entirely clear about the requirements, so what would happen to the following inputs:
    "12 34"
    "12a34"
    "a"But basically you'll probably want String.split(), Integer.parseInt() and a loop.

  • Will the memory leak for queue when used in producer and consumer mode in DAQ to transfer different sized array.

    In the data acquisition, I use one loop to poll data from hardware, another loop to receive the data from polling loop sent by queue.
    But everytime the size of the transferred data array may not be the same, so the system may assign different array size and recycle very frequently.
    Will it cost memory leak. Or will it slow down the performance, since the array size is not fixed, so every time need to create a new sized array.
    Any suggestion or better method. 
    Solved!
    Go to Solution.

    As i understand your description, your DAQ-loop acquires data with the setting '-1' for samples to read at the DAQmx read function. This results in the different array sizes.
    Passing those arrays directly to a queue is valid and it does not have significant drawback in performance (at least as far as i know) and it definetly does not leak memory.
    So the question is more or less:
    Is it valid that your consumer receives different array sizes for analysis? How does your consumer handle those arrays? 
    hope this helps,
    Norbert 
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Creating dynamic sized arrays and filling them automatically on speedy 33

    hi all,
    I am trying to create dynamic sized arrays on Speedy-33. Specifically, depending on the user input, I want to be able to create
    arrays with 128 or 256 elements and fill them automatically. However,
    array constant element is fixed for Speedy 33; thus I have to manually set the
    size of the array with the mouse and enter the values in to the array by
    myself. I want to make this tedious process automatic. Would this be possible? thanks so much for comments!
    ~casiopea

    Casiopea,
    There is a really great article on using arrays with LabVIEW DSC which can be found here:
    How Can I Be Successful With Arrays In the LabVIEW DSP Module?
    One of the biggest things that should be noted about DSP is that there is no dynamic memory allocation.  Your array size must be fixed, and thus, your array needs to be initialized by using a constant. 
    An easy way to initialize an array constant that has many elements that are all the same is to simply create a numeric constant that has the value that you want.  Then, create a new blank array constant and drag the numeric into it.  In the index input for the array constant, type in the index of the last element that you want to be initialized.  Then type in the value in the element that is displayed and all of the elements before it will be initialized to the default value of the numeric constant that you dropped into the array constant.  I hope this helps.  I would really recommend reading through that article, as it has a lot of great information about using arrays with DSC.
    Brian Coalson
    Software Engineer
    National Instruments

  • Fixing an array index's out of range error

    Hi,
    Am stuck in an eLearning project that I am working on and need some help fixing a 2007 error that seems to point to an index for an array being out of range.
    Here is the previous posting where there are more details: http://forums.adobe.com/message/4685789#4685789
    With much help (thank you once again kglad), the script looks like:
    var index:int = 0;
    var numToDisplay:int = 10;
    var groupA:Array = ["1","2","3"]
    var groupB:Array = ["4","5","6"]
    var groupC:Array = ["7","8","9"]
    var word_array:Array = [];
    var i:int;
    for(i=0;i<3;i++){
    word_array.push(groupA[groupA.length*Math.random()]);
    for(i=0;i<3;i++){
    word_array.push(groupB[groupB.length*Math.random()]);
    for(i=0;i<3;i++){
    word_array.push(groupC[groupC.length*Math.random()]);
    This is used in another part of the script:
    function randomWord() {
        if(index<numToDisplay){
            wordT.text=word_array[index++];
            t.reset();
            t.start();
        } else {
      wordT.text= "";
        // display score
    The error message (2007) points to:
    wordT.text=word_array[index++];
    When I trace (word_array)  I get
    Out of range index for this array?
    How can I fix this out of range index?
    Any help appreciated.

    Since there appear to be only 9 elements getting added to the array, and your numDisplay is set to be 10, your condition ( if(index<numToDisplay){ ) allows index++ to get to 10, which will be out of range for your array.  See if changing the value of numDisplay to 9 solves the problem.

  • Fixed sized tables

    I have a website and I am trying to use a template that will
    keep my pages the same throughout. I put a table cell on the left
    with my links and made it 220 pixels. On the Editable region, I
    also put in a table cell, hoping to keep the two columns consistent
    throughout but it's not working. some pages, it does work, I go and
    check and the ones that are not staying consistent look the same in
    Dreamweaver.
    HELP! I'm going nutz! You can visit my site:
    http://www.angeldoggie.com
    src="/webforums/forum/images/i/expressions/face-icon-small-confused.gif"
    border="0">

    Can you point to a specific page and tell us what it is that
    you don't want
    to happen?
    By the way, the home page of your site has several errors
    your should fix -
    http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fwww.angeldoggie.com%2F
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "galen1artist" <[email protected]> wrote in
    message
    news:fnge3b$ano$[email protected]..
    >I have a website and I am trying to use a template that
    will keep my pages
    >the
    > same throughout. I put a table cell on the left with my
    links and made it
    > 220
    > pixels. On the Editable region, I also put in a table
    cell, hoping to keep
    > the
    > two columns consistent throughout but it's not working.
    some pages, it
    > does
    > work, I go and check and the ones that are not staying
    consistent look the
    > same
    > in Dreamweaver.
    >
    > HELP! I'm going nutz! You can visit my site:
    >
    http://www.angeldoggie.com
    src="/webforums/forum/images/i/expressions/face-icon-small-confused.gif"
    border="0">
    >

  • How to fix sizing for album artwork?

    So I made an album cover for a song that is not yet on iTunes and it's not the correct size. I've tried resizing it and everything and I just can't seem to fix it. It doesn't show up correctly on my iPod either so please help! Here's a picture of what I'm talking about, in the middle row there's a difference between the two covers.

    If the photo is not square, iTunes will leave extra space. 
    Before adding it to iTunes, use Picasa, PictureIt, or some other photo editor to crop it to a square shape.

  • Fixed sized capacity resources

    The customer has an oven that takes 200 kg. If order quantity is less than 200 kg the operation will take 4 hrs if the quantity is more 201 - 400 kg it will be 8 hours etc. How do I set up the workcenter and what data should be on the routing operation to achieve this?
    Could anyone give me an example code for a formula in Capacity planning that uses fixed size capacities.

    Hi
    you can go through the following notes which is given an example:
    Exactly 200 workpieces fit into an annealing furnace. However 201 workpieces have to be annealed. In this case two runs are necessary, the annealing time is doubled.
    The execution time is the sum of the setup time and the annealing time multiplied by the number of runs. This is expressed in the following formula
    F = SET + ( VOL_B / B * ( LOT- 1) DIV VOL_F + 1) * RUN
    The meaning of the formula parameters and the origins of their values are given in the table below.
    Formula Parameter
    Meaning
    Origin
    B
    Base quantity
    General operation value
    LOT
    Lot size
    General operation value
    RUN
    Annealing time
    Standard value
    SET
    Setup time before processing
    Standard value
    VOL_B
    Volume of the base quantity
    Standard value
    VOL_F
    Volume of the annealing furnace
    Standard value or
    Formula constant
    You can assign just one operation segment, for example the processing segment, a formula to calculate the execution time of the whole operation. You do not assign formula to the other segments
    Calculations with Several Formulas
    Since the program adds together the times of two segments, you can use two formulas, F1 and F4 for the segments.
    Operation segment: Set-up
    F1 = TR
    Operation segment: Process
    F4 = ( VOL_B / B * ( LOS - 1) DIV VOL_GO + 1) * TE
    This is useful, if you are interested in the times of the individual segments.
    The formulas and parameters used here, F, F1, F4, B, LOT, SET, etc., are only valid in this example. In the SAP standard system formulas and parameters are defined for various applications with different formula key words and parameter IDs.
    Regards
    YMREDDY

  • Keeping a grid a Fixed sized, when the vindow is resizes

    Hi I have a problem with a "simple" swing app, i have made a program to take alot of user input, i have it in a GridLayout(9,1) if i just add this to frame.getContentPane(); then it looks nice, but if i then changes the size of the vindow (make it fullscreen), then it looks like hell :(
    I have tryed a BorderLayout, but the CENTER bit has the same problem. Looks like this:
    frame = new JFrame("UNF " + lokal +  " Indskrivningsprogram");
              Container contentPaneAll = frame.getContentPane();
              BorderLayout bLay = new BorderLayout();
              contentPaneAll.setLayout(bLay);
                    Container contentPaneCenter = new Container();
              GridLayout gLay = new GridLayout(9, 1);
              gLay.setVgap(-5);
              contentPaneCenter.setLayout(gLay);
                  //Adds alot of stuff to contentPaneCenter
              Dimension d = contentPaneCenter.getPreferredSize();
              contentPaneCenter.setMaximumSize(d);
              contentPaneCenter.setMinimumSize(d);
              contentPaneAll.add(contentPaneCenter, BorderLayout.CENTER);What i want is for the center part tp keep contentPaneCenter.getPreferredSize(); and then just add "gray" around it if in fullscreen.
    Bedst regards
    Grue
    Ps sorry for my bad eng, not a native speaker...

    853384 wrote:
    .. What i want is for the center part tp keep contentPaneCenter.getPreferredSize(); and then just add "gray" around it if in fullscreen.Put it as a single component into a <tt>GridBagLayout</tt> with a <tt>null</tt> constraint, much as I did for the 'gradient' image in this Nested Layout Example.
    If that does not answer your question, I suggest you post an SSCCE (like the linked example, & as opposed to 'code snippets').

  • Local variable for an Array of fixed size

    Hello,
    I have a two multirate loops in a VI. 
    In one loop, I want to refer an fixed sized array initialized in the other loop.
    But I coudn't name the array, so I can't refer it.
    Is there any way to refer it?
    Thanks,
    Young.

    If you need a local variable, there is no other way than to create an indicator for it.
    In LabVIEW there is no "fixed length" array : you can always add or remove an array element, and you don't need to declare it as in other languages. They are intrinsic dynamic objcets. Of course, the memory manager has to cope with this, that's why it's often better to initialize an array, to give it its final size immediately, resulting in faster running programs. However, this is only noticeable with relatively large arrays (> 10000-100000 elements).
    May be you should explain in more details what you intend to do, because trying to reproduce a C approach in LV is probably not the best thing to do. For instance, you said that you are initializing your array in a first loop. You mean that you re-initialize the array at each iteration ? I suppose no, so may be you could put the initialize step out of the loop, and wire the array to your two parallel loops.
    Remember also that local variables are not always good programming solutions, since using them will generate copies of their content each time they are refered to. And that can low down your program very significantly...
    Message Edité par chilly charly le 11-05-2005 05:05 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Expand a 2D array horizontally

    Hi
    I am writing a code to insert an element into a 2D array. The problem is I can add the element only in the rows direction (vertically). I want to be able to add the element in the columns direction (horizontally). Do u know how? I attached my program here too. Thanks
    Attachments:
    add to array.vi ‏24 KB

    Your idea is slightly flawed, because in a typical 2D array, you cannot just add a single element without resizing the entire array.
    Since you don't give a choice to add either horizontally or vertically with two buttons, how should the program decide where to add?
    Could it be you want to fill the first three horizontally, then continue on the next row, and so on? (see attached modification).
    Typically it is better to start with a fixed sized array of empty strings (e.g. 3x5), then use "replace array element" to enter a new value at the desired location. Constantly resizing arrays is inefficient.Message Edited by altenbach on 03-15-2005 04:44 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    add_to_arrayMODIFIED.vi ‏44 KB

  • Motion Assistant Contour Array Points - Optimal Array Size?

    I am working with the NI Motion Assistant API and plyaing around with the Contour Move generation where I feed a set of X, Y target points to the Set Contour Move Properties.
    One of the inputs is Profile Calculation Constraint - Array Size, Constraint Value (which would be the array size to use).
    I am wondering if there is a way to calculate the "optimal" array size for any particular move?  I know I can have too few - can I have too many points in an array (being reasonable here and not planning to use the whole 2^32 size allowed).
    Thanks.
    Ryan Vallieu
    Automation System Architect

    Hi Ryan,
    Unfortunately, I'm not so sure I have a good answer for you. I'll evaluate some of the pros and cons below and then ultimately make a recommendation:
    Constraint Type: Array Size
    Pros
    You always have a fixed sized array of setpoints. If you are using a 73xx card, this simplifies setting up your contour buffer. It also avoids using a lot of memory.
    Cons
    For long moves, you could have a long time and large distance between position setpoints. The motion card will do a spline interpolation to smooth the move, but the splining algorithm is only so good.
    If you are sending the contour setpoints to a motion card, you don't know the interval between setpoints (although this isn't difficult to obtain).
    Constraint Type: Sampling Time
    Pros
    Regardless of the move, you always have a fixed time between setpoints. As long as your sampling time isn't too large, even fast moves should execute accurately.
    Cons
    For a long move, you could generate a lot of setpoints that consume a lot of memory.
    Setting up contouring buffers can be trickier.
    Conclusion
    It depends on what you expect the end customer to be doing. I prefer using the sampling time constraint since it is more robust for fast, long moves (and still good for slow, short moves). It will make creating contour buffers more difficult, but there is an example (Two-Axis Smart Contouring.vi) that shows how to dynamically update the buffer. Ultimately, I think it is better to focus on accurate moves than minimizing memory consumption.
    If you decide to go with the sampling time method, I would start with a constraint value of .01, since 10msec is the shortest interval when configuring a contour buffer. Try and generate some position profiles to see how big the arrays are. For optimizing, it is just a tradeoff between array size and the accuracy of the generated motion profile.
    Thanks,
    Paul B.
    Motion Control R&D

  • Thread Contention

    I've written a producer/consumer type of application. the producer receives data input (speed and time) over a serial connection and places it in a queue of sorts, set up much like the examples at Sun. The consumer picks up the values, calculates a speed and moves an animation object across a display.
    I've put both the consumer and producer programs in their own threads. the driver program starts the producer program in its thread and calls an openConnection method to open a serial connection. I then call a startCollecting method that begins reading serial input. The input is dumped in the queue, which has a capacity of 5 values. If the producer fills all five values, it goes into a wait state. the consumer is supposed to pick up the values, freeing the producer to place more values in the queue. My problem is once the producer goes into its wait state, everything freezes, including the driver program interface, and the visual display the consumer is running in.
    If I do not call the openConnection and startCollecting separately, but rather just start the producer thread and let it open a connection and start collecting automatically all runs well. It seems the problem exist whenever I attempt to access methods inside the threaded program.
    Any help would be greatly appreciated. Have not found any really examples of how to resolve this approach.

    I've put both the consumer and producer programs in
    their own threads.good.
    the driver program starts the
    producer program in its thread and calls an
    openConnection method to open a serial connection. I
    then call a startCollecting method that begins reading
    serial input. The input is dumped in the queue, which
    has a capacity of 5 values. If the producer fills all
    five values, it goes into a wait state. the consumer
    is supposed to pick up the values, freeing the
    producer to place more values in the queue. My problem
    is once the producer goes into its wait state,
    everything freezes, including the driver program
    interface, and the visual display the consumer is
    running in. this sounds like you possibly missed something in the area of thread synchronization. did you invoke notifyAll() after you put somthing in the queue?
    the typical queue implementation looks like this:
    package farmerworker;
    import java.util.*;
    * A thread safe queue used to synchronize farmers and workers. Farmers put
    * objects into the queue and workers retrieve them. Workers may arbitrarily
    * invoke {@link #dequeue()}. Their thread blocks until an instance can be
    * retrieved from the queue or the thread is interrupted. <p>
    * technically {@link #enqueue( Object )} and {@link #dequeue()} are
    * synchronized using {@link #wait()} and {@ #notify()}.
    * @author    klemme
    * @created   24. September 2001
    * @version   $Revision$
    public class Queue {
         * Checks whether there are objects in the queue.
         * @return   'true' if there are instances in the queue. WARNING: in a
         *      multithreaded environment it is only reasonable to invoke this
         *      method when holding a lock on this instance, i.e. in a <code>synchronized</code>
         *      block.
        public boolean isEmpty() {
            synchronized ( lock ) {
                return queue.isEmpty();
         * Return the number of objects currently in the queue.
         * @return   a value >= 0
        public int size() {
            synchronized ( lock ) {
                return queue.size();
         * Put an object into the queue.
         * @param obj  the instance to enque
        public void enqueue( Object obj ) {
            synchronized ( lock ) {
                queue.add( obj );
                lock.notify();
         * Retrieve something from the queue. This method blocks until either an
         * Object can be retrieved from the queue or this thread is interrupted.
         * @return                          the next Object in the queue
         * @exception InterruptedException  in case of premature termination of this
         *      thread.
        public Object dequeue()
            throws InterruptedException {
            synchronized ( lock ) {
                while ( isEmpty() ) {
                    lock.wait();
                return queue.remove( 0 );
        private List queue = new LinkedList();
         * The lock on which this instance synchronizes.
        protected final Object lock = queue;
    [/code}]instead of synchronizing on "lock" you can just synchronize methods.  then you have to invoke notifyAll() and wait() on "this".  you can also change the conditions when the queue accepts new input.  this Queue is unbounded, but you can implement a size limit via a condition testing for the size in enqueue(). (typically this is easier done then working with a ring buffer in a fixed sized array, since then you need two indexes etc. and the overhead of a LinkedList is not too big. - btw: LinkedList is faster than ArrayList if you don't need indexed access like in this case.)
    regards
    robert

  • I get an error code 1 from Unflatten From XML

    I'm not quite sure why I'm getting this error code. The code looks fine to me. I hope I'm not missing something obvious. I imagine maybe it's one of the datatypes but I'm not sure. See attached VI (8.6)
    CLD (2014)
    Attachments:
    XML read write.vi ‏10 KB

    How observant of you. I was just going to post the same conclusion. The data type that came off an FPGA "read /write control" node. 
    Neat! Now we have fixed sized arrays in LV! 
    The attached shows it failing a "flattened string to variant" and the different type strings the two have.
    Message Edited by InfiniteNothing on 11-07-2008 02:35 PM
    CLD (2014)
    Attachments:
    Comparison.vi ‏10 KB

  • Controls lose data binding when added to cluster

    Please forgive me if this is a newbie question, but I can't seem to find an answer.
    In a nutshell, I have an array (constant) of strings and a cluster of booleans.  I want to search the name of each boolean in the cluster for a match to a string in the array and perform an action for each match.  Say I want to turn on all booleans that match.
    The problem is that the booleans are bound by datasocket - to OPC server to PLC.  So when I add a boolean to the cluster, the data binding is dropped.  Attempts to reassign data binding are unsuccessful.  If I move the control outside the cluster and reassign data binding, it works.  There are a fair number of booleans so I want to avoid wiring them one by one.
    I am using LabVIEW 8.6 and there is a known bug similar to this for arrays of fixed size.  However I don't totally understand the solution and how I would apply it to a cluster:  "Uncheck autopreallocate arrays and strings in the VI properties execution category for all VIs not intended to run on an FPGA."  There is no listing for clusters.  Could I be doing something wrong?  Should I be using shared variables instead of data binding?
    3OLE2573
    Return
    DataSocket and Fixed Size Array Do Not Work
    You cannot use front panel DataSocket data binding with fixed-sized arrays.
    Workaround: Uncheck autopreallocate arrays and strings in the VI properties execution category for all VIs not intended to run on an FPGA.
    Message Edited by Katelyn on 08-18-2009 12:14 PM

    Peter,
    Thanks. i will separate this in 3 questions.
    I posted the whole thing, so people could copy the code on
    Flex and tested to see what I am talking about.
    "evt.target.selectedItem should be a <module> element.
    Is that not happening?"
    Yes, when loading is a module. Once a click on a list item I
    get the following error:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    at SPADE2/::changeHandler()
    at SPADE2/__cList1_change()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()
    at
    mx.controls.listClasses::ListBase/mx.controls.listClasses:ListBase::mouseUpHandler()
    at mx.controls::List/mx.controls:List::mouseUpHandler()
    If a click dismiss all, I can click on the tabs and the
    content on the list changes as expected, but when clicking on the
    list items, they don't work.
    If a click on the video tab the state changes, but I have to
    click on the list twice to play a video. After that I the list
    items for the other tabs work.
    Gilbert

Maybe you are looking for

  • How to fix problem with opening pdfs in Windows 8.1 with Adobe Reader XI?

    Every time I try to open a pdf on my new laptop with Adobe Reader XI, I get a message than either the file is not supported or its damaged. But it still opens fine on my old laptop with Windows 7. Any suggestions?@

  • SharePoint Designer 2013 "CallHTTPWebService" activity throws error in Status Response variable as 'Forbidden'

    Dear All, When i pass the REST Query in Sharpoint Designer 2013 i tried to write the history with responsestatuscode which returned as "Forbidden" 1. Rest query works fine with Internet explorer and results are returned. 2. Query works fine in Fiddle

  • DNS, Certificates, and Active Directory - School Setup Issues

    Our school has been piloting a small iPad depolyment.  I have been struggling with getting Profile Manager to work correctly since August of last year. Here's the setup: 1. Active Directory DNS/DHCP server (set as "school.local"--yes, I know .local i

  • Multiple dmz hosts? ps3+xbox360

    Hi! I'm having difficulties in setting multiple dmz hosts. Both my ps3 and my xbox 360 require me to set them as the dmz host. However, in the router's settings page, there's only one space for ip entry to enable dmz. Thus far, my only solution has b

  • Exporting in encore 2.0

    I'm using encore 2.0 at the moment to make a DVD out of a avi. file. The file is about 700MB large. At the moment I don't need any buttons or menus or anything, I just want to make the DVD as smooth as possible. The problem is wehen I'm building the