Sorting elements within an array

Hi, I'm working on a small piece of software and I've got to a little problem. The software has a Train class, which has two integers (departureTime and arrivalTime). In my main controlling class, there are methods to add Trains to a Trains array (called "trains"), to delete these trains, to display the trains present in the form of a timetable, etc.
I am trying to get it so that the trains, when the user decides to display the timetable, are display in ascending order based on their departureTime. I can't use a simply Array.sort() as the array is an array of Train objects, and not of the integers themselves.
I've played round with FOR loops, etc. I have a Time class, which has in it a method that goes as follows...
public int compare(Time t) {
// compare this Time with Time t
if (this.minutes == t.minutes) return 0;
if (this.minutes > t.minutes) return 1;
return -1;
So I can easily find out whether the individual train is sooner or later than the other, but it is a case of doing this in such a way that the trains end up in an order in the array of ascending numerical order by the departureTime.
A seperate array could be created, "displayTrains" which holds them in, that would be fine. I only need the trains to be sorted by departuretime for the display method, they can be in any order in the rest of the program.
Any ideas? The following is what I have so far for the display method, though where the sorting code will go there is a comment....
//method to display the trains currently in the system, in departure time order
public static void displayTrains() {
String trainsDisplay="", sdeptTime, sarrTime, sjourTime;
Time deptTime = new Time();
Time arrTime = new Time();
Time jourTime = new Time();
Time sortDeptTimeA = new Time();
Time sortDeptTimeB = new Time();
Train [] displayTrains = new Train[numberTrains];
int counter1=0, counter2=0, counter=0, compare, arrayPos=0;
boolean earlier=false;
//code to sort here
trainsDisplay = "Loughborough to Leicester Train Timetable:\n\n";
for (counter=0; counter<numberTrains; counter++) {
deptTime = trains[counter].getDepartureTime();
arrTime = trains[counter].getArrivalTime();
jourTime = trains[counter].getJourneyTime();
sdeptTime = deptTime.toString();
sarrTime = arrTime.toString();
sjourTime = jourTime.toString();
trainsDisplay = trainsDisplay + "Departure: " + sdeptTime +
" Arrival: " + sarrTime + " Duration: " + sjourTime + "\n";
JOptionPane.showMessageDialog(null, trainsDisplay);
I would really appreciate any ideas people have, I'm learning Java at the moment, so if its really simple, then the code would also be greatly appreciated!
Kindest regards,
David.

Okay, create another class that implements the Comparator interface, e.g.TrainComparator and then one of its methods should be compareTo(Object,Object)
public class TrainComparator implements Comparator {
    public int compareTo(Object o1, Object o2) {
}How compareTo is implemented is up to you. But you should return a negative int if o1 is less than o2, 0 if o1 is equal to o2 and a positive integer if o1 is greater than o2. You can cast o1 and o2 as Train objects and call methods from that class to help you.

Similar Messages

  • Sort an an arrayList by the first element of an array

    Hi,
    I am really struggling trying to sort an arratList of arrays. I have an arrayList
    ArrayList<String[]> myArrayList = new ArrayList<String []>(100);
    Within this array I have may arrays with 2 elements
    String[] myArray1 = {"Peter", "London"};
    String[] myArray2 = {"John", "London"};
    String[] myArray3 = {"Tony", "Birmingham"};
    I add all these arrays to the arrayList and want to sort by the first element of the array. Basically I expect the final arrayList to be in the order of:
    "John", "London"
    "Peter", "London"
    "Tony", "London"
    Thanks
    Peter

    Hi,
    I am really struggling trying to sort an arratList of
    arrays. I have an arrayList
    ArrayList<String[]> myArrayList = new
    ArrayList<String []>(100);
    Within this array I have may arrays with 2 elements
    String[] myArray1 = {"Peter", "London"};
    String[] myArray2 = {"John", "London"};
    String[] myArray3 = {"Tony", "Birmingham"};
    I add all these arrays to the arrayList and want to
    sort by the first element of the array. Basically I
    expect the final arrayList to be in the order of:
    "John", "London"
    "Peter", "London"
    "Tony", "London"
    Thanks
    PeterThis can be done by using
    Collections.sort(myArrayList, new Comparator<String[]>() {
    public int compare(String[] s1, String[] s2) {
    if (s1.length() <1) {
    return -1;
    if (s2.length() <1) {
    return 1;
    return s1[0].compareTo(s2[0]);
    });

  • Sort within an array?

    public class Input3
         private String[] input = new String[40];
         private static int StringNum = -1;
         public static final int NUMBER_OF_TEAMS = 3;
         public static final int NUMBER_OF_PLAYERS = 5;
         public Input3()
              //The first six inputs will be for the first team
              input[0] = "LAKERS";
              input[1] = "Kobe Bryant";
              input[2] = "Derek Fisher";
              input[3] = "Shaquille O'Neal";     
              input[4] = "Karl Malone";
              input[5] = "Brian Cook";
              //The next six inputs will be for the second team
              input[6] = "MAVERICKS";
              input[7] = "Antoine Walker";
              input[8] = "Dirk Nowitzki";
              input[9] = "Tony Delk";
              input[10] = "Shawn Bradley";
              input[11] = "Travis Best";
              //The next six inputs will be for the third team
              input[12] = "KNICKS";
              input[13] = "Mike Sweetney";
              input[14] = "Allan Houston";
              input[15] = "Howard Eisley";
              input[16] = "Kurt Thomas";
              input[17] = "Shanon Anderson";
         //This method returns the strings one after the other.
         public String getNextString()
              StringNum++;
              return input[StringNum];
    }What I'm supposed to do with this is sort that data by last names within each team. By that I mean I have to sort input[1] through input[5] by last names, input[7] through input[11] by last names, and same for the Knicks team. I'm not sure how to do 3 separate sorts within an array.
    The output should look like this:
    KNICKS:
    Sharon Anderson
    Howard Eisley
    Allan Houston
    Mike Sweetney
    Kurt Thomas
    Any help is greatly appreciated!

    Yeah, I don't really understand it. But my professor actually gave us that code to work with to be part of a bigger assignment. I actually just posted another question about the same assignment if you want to look at that to see if it might help.
    I dunno how to use the insert link button on here so I'll just let you copy and paste if you are interested in helping me out... Thanks!
    It's here >>> http://forum.java.sun.com/thread.jspa?threadID=5268839

  • Change properties of a cluster element withing an array of clusters

    Hello all,
    I have an array of cluster that is shaped as a line with different display elements.
    A list or a tree wouldn't have made it, so I had to use a cluster and make a table.
    The problem is that I want to change not only the text but also the text color.
    Individually.
    I found this :
    http://www.ni.com/example/30904/en/
    But it change the property in all the clusters in the array, not just the one I need.
    Some people have the same problem :
    http://forums.ni.com/t5/LabVIEW/Reference-to-Array-of-Clusters-with-an-array-element/td-p/1006427
    http://forums.ni.com/t5/LabVIEW/Different-set-of-values-for-two-rings-in-an-array-of-clusters/m-p/10...
    http://forums.ni.com/t5/LabVIEW/array-of-clusters-get-references-to-all-the-clusters/td-p/1079456
    http://forums.ni.com/t5/LabVIEW/How-can-I-reference-the-properties-of-a-control-in-a-cluster-in/m-p/...
    http://forums.ni.com/t5/LabVIEW/Writing-only-to-certain-cluster-elements-in-an-array-by/m-p/2200728
    http://forums.ni.com/t5/LabVIEW/Update-Properties-Of-One-Control-In-An-Array/m-p/3015501
    http://forums.ni.com/t5/LabVIEW/Array-of-clusters-and-in-the-cluster-is-a-bar-meter-how-can-I/m-p/15...
    http://forums.ni.com/t5/LabVIEW/Property-node-of-a-control-inside-of-cluster-inside-an-array/m-p/946...
    Obviously, while in a list/table or tree you can change the property of an individual
    cell (font, color) you cannot do it within an array of cluster, by some sort of magic,
    the property of a cluster element (font, color) are all linked together, hence rendering
    the use of an array worthless.
    A possible hack is proprosed by using control masking, setting one visible and the
    other invisble, swapping their position, whatever. It's a hack you have to perform,
    hence add another code to maintain.
    Is that still the case or is there now a more official way to handle individual cluster
    properties, not just its data ? After all that's a common real-life example that should
    be handled by Labview. In my opinion.
    David Koch
    Solved!
    Go to Solution.

    altenbach wrote:
    One of the elements could be a 2D picture indicator of about the same size. You can write text in any color using picture functions.
    Here's what I had in mind. Seems to work just fine (I would fine-tune the font, picture border, etc. but this should get you started).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ColorText.png ‏13 KB
    ColorText.vi ‏9 KB

  • Can't duplicate movieclips as an array within an array

    Hello.
    I have an animation that loads an xml into it and traces back
    an array within an array. I have tried to apply this to duplicated
    movieclips thereby creating a structured set of links. What I am
    trying to do is this:
    Chicken Nuggets
    __Compression
    __Texture
    __Disgust
    Mega Warhead
    __Taste
    __Hardness
    __Pain
    This traces fine but I can't seem to get the duplicated
    movieclips to assemble in this fashion.
    The code for the XML is as follows:
    var controlArray:Array;
    var variable:Array;
    var testTopic = new Array ();
    var test = new Array ();
    var controlsXML:XML = new XML();
    controlsXML.ignoreWhite = true;
    controlsXML.onLoad = function(success:Boolean){
    if (success){
    var mainnode:XMLNode = controlsXML.firstChild;
    var controlNodes:Array =
    controlsXML.firstChild.firstChild.firstChild.firstChild.childNodes;
    var list:Array = new Array();
    for (var i:Number = 0; i < controlNodes.length; i++) {
    var personnode:XMLNode = controlNodes
    .attributes.Name;
    trace(personnode);
    testTopic.push (new struct (personnode));
    var specificNode:Array = controlNodes.childNodes;
    for (var j:Number = 0; j < specificNode.length; j++){
    var itemnode:XMLNode = specificNode[j].attributes.Variable;
    trace(itemnode);
    test.push (new struct2 (itemnode));
    printer ();
    printer2 ();
    } else {
    trace('error reading XML');
    controlsXML.load ("controls3.xml");
    The code for the movieclip duplication is as follows:
    x = 50;
    function printer ()
    for (m = 0; m < testTopic.length; m++)
    duplicateMovieClip ( slotTopic, "slotTopic" + m, m );
    slotTopic = eval ( "slotTopic" + m );
    slotTopic._y += x;
    slotTopic.slotTopicContent.text = testTopic[m].personnode;
    function printer2 ()
    for (k = 0; k < test.length; k++)
    duplicateMovieClip ( slot, "slot" + k, k );
    slot = eval ( "slot" + k );
    slot._y += x;
    slot.slotContent.text = test[k].itemnode;
    function struct (personnode)
    this.personnode = personnode;
    function struct2 (itemnode)
    this.itemnode = itemnode;
    On the stage are two movieclips, titled "slotTopic" and
    "slot". Within those are dynamic text boxes titled respectively
    "slotTopicContent" and "slotContent". When I preview this file it
    only displays the text within the "slot" movieclip and it lists all
    six of the subtopics with no break. So, there are two dilemmas:
    1) The movieclips won't duplicate into the structured set of
    links that I want.
    2) "slotTopic" is not displaying text at all.
    If anyone has any advice, I'd really appreciate it.
    Thx!

    ok, I'm sorry but there are quite a few things wrong here.
    first though, when posting code please use the 'attach code'
    button.
    1) i can't imagine that you have a XML structure as deep as
    your calling to or the need for it with the limited amount of
    infomation your pulling, in addition your storing the info in
    attributes, so I can't see how this would work, it may 'trace' out
    the right text (somehow) but it's not getting into the arrays
    properly.
    2) you do not assign an attribute value to a XMLNode, and
    then try to push it into an array.
    3) you do not call a method (struct or struct2) using the
    'new' operator. this is how you envoke a new 'class' instance.
    4) do not use 'x' as a variable name as it is a reserved var
    in flash, assigned to an Object instance.
    5) the duplicateMovieClip() method needs to be called upon
    the existing clip as in:
    slotTopic.duplicateMovieClip('slotTopic'+m, m);
    additionally you can pass the _y placement within the
    initObject.
    6) you do not need to use eval, it isn't doing anything here,
    you will gain the correct path by calling duplicateMovieClip
    correctly.
    7) the reason why slotTopic is not being displayed at all is
    because of the second loop, you are duplicating the clips
    (incorrectly) into the same depths thereby replacing all of the
    contents of the slotTopic depths previously constructed.
    the solution to this problem is to construct both items with
    the same loop but increament one of the depth assignments by a
    specific number, in other words at depths much higher or at least
    different, than that of the first element, as in:
    slotTopic.duplicateMovieClip('slotTopic'+m, m, {_y:50});
    slot.duplicateMovieClip('slot'+(m+100), m+100, {_y:50});
    again I'm sorry man, but it will take some work to sort this
    out.

  • How to make use of adjacent data elements within the same buffer

    Hi,
             Does anyone know how to make use of adjacent data elements within the same buffer? To make my question clearly, I would like to give you an example. In my application, I set "sample to read" as 10 which means at each loop 10 data samples will be taken into a buffer. Now, what I would like to do is to do some calculations on adjacent data samples in same buffer. I tried to use "shift register" for this, but it seemed to me that it only can deal with the calculation between data from adjacent loops. In other words, it skips 9 data elements and take the 10th one for the calculation.
             Here I also attach my VI showing what I did.
        Thank you very much in advance,
                            Suksun
    Attachments:
    wheel_encoder_1.vi ‏98 KB

    Hi Suksun,
          I hope you'll forgive me for distilling your code - mainly to understand it better.  I tried to duplicate your logic exactly - which required reversing the "derivatives"-array before concatination with the current samples array.  As in your code, the last velocity is being paired with the first position.  If first velocity is really supposed to be paired with first position, just remove the "Reverse 1D Array" node.
    cheers
    Message Edited by Dynamik on 01-07-2006 03:17 AM
    Message Edited by Dynamik on 01-07-2006 03:19 AM
    When they give imbeciles handicap-parking, I won't have so far to walk!
    Attachments:
    encoder2.GIF ‏14 KB
    encoder2.vi ‏102 KB

  • How to pass a single element in an array to XSL from BPEL

    In a bpel (2.0) process I have a for-each loop iterating through a list in the original input document.  Within that loop I need to construct an  input document  for a call to a web service based on data in the current node of the list objects I am looping through.
    Constructing the input document via BPEL assign activity copies within the for-each loop is an option but due to the complexity of that document I would prefer to use XSL.  But I don't know how to pass the index information (ie. the for-each counter) into XSL and use it there (and I would prefer not to have to do so, since that will prevent use of the XSL GUI in jdev), so I would prefer to send  the current node of the list as input to XSL instead.
    Is it possible to pass a sub-section of an XML document (e.g. one node in the array) as input into XSL rather than the whole document?  In other words, I would like to send the current array element from the original input document rather than the entire original input document because I will be using the data within that array element to create the web service input document.
    Example:
    <forEach parallel="no" counterName="i"
                         name="ForEachEntry">
                  <startCounterValue>1</startCounterValue>
                  <finalCounterValue>$numTimeEntries</finalCounterValue>
    If I used the BPEL assign activity to populate the input document I would need lots of copies similar to this:
                  <copy>
                      <from>$inputVariable.OteStgTimecardCollection/ns3:OteStgTimecard[1]/ns3:oteStgTimecardDetailCollection/ns3:OteStgTimecardDetail[$i]/ns3:origtransactionreference</from>
                      <to>$InvokeOteDetailAbsenceErrorStatusService_OteAbsenceDetailFailureService_InputVariable.OteAbsenceDetailFailureServiceInput_msg/ns19:OrigTransactionReference</to>
                  </copy>
    I would prefer to send the current list object as an input variable into an XSL transform: 
         $inputVariable.OteStgTimecardCollection/ns3:OteStgTimecard[1]/ns3:oteStgTimecardDetailCollection/ns3:OteStgTimecardDetail[$i]
    Is there syntax in bpel that would do that?
    Thanks

    You need use While Element and use Array like Element[number]
    With While element you iterate <employee> node
    and with Element[number] you can extract information from that node.
    I wrote a BPEL that scan a XML file, the input is:
    <cliente>
            <codigo>01</codigo>
            <nombre>Deiby Mauricio Gomez</nombre>
                    <productos>
                            <producto>
                                    <nombre>Camisa Polo</nombre>
                                    <precio>50</precio>
                            </producto>
                            <producto>
                                    <nombre>Pantalon Lona</nombre>
                                    <precio>100</precio>
                            </producto>
                    </productos>
            </cliente>
            <cliente>
            <codigo>02</codigo>
            <nombre>Julio Cesar Ayapan</nombre>
                    <productos>
                            <producto>
                                    <nombre>Camisa Polo</nombre>
                                    <precio>50</precio>
                            </producto>
                    </productos>
            </cliente>
    In my BPEL I added up all article prices and after that I write to txt file the client and the Total.
    Example:
    Deiby Gomez, 150
    Cesar Ayapan, 50
    My while element is this (Please pay attention in bold words):
      <while name="While1"
               condition="bpws:getVariableData('variable1')&lt;=count(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente'))">
          <sequence>
            <assign name="Assign1">
              <copy>
                <from expression="sum(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:productos/ns4:producto/ns4:precio'))"/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:cantidad"/>
              </copy>
              <copy>
                <from variable="Receive1_input_files" part="body"
                      query='/ns4:clientes/ns4:cliente[number(bpws:getVariableData("variable1"))]/ns4:codigo'/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:id"/>
              </copy>
            </assign>
            <invoke name="Invoke1" inputVariable="Invoke1_process_InputVariable"
                    outputVariable="Invoke1_process_OutputVariable"
                    partnerLink="ValidacionBancos2WS" portType="ns5:BPELProcess1"
                    operation="process" bpelx:invokeAsDetail="no"/>
            <switch name="Switch1">
              <case condition="bpws:getVariableData('Invoke1_process_OutputVariable','payload','/ns5:processResponse/ns5:resultado')='true'">
                <bpelx:annotation>
                  <bpelx:pattern>Si el cliente es aprobado</bpelx:pattern>
                  <bpelx:general>
                    <bpelx:property name="userLabel">Si Aprobado</bpelx:property>
                  </bpelx:general>
                </bpelx:annotation>
                <sequence>
                  <assign name="Assign4">
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query='/ns4:clientes/ns4:cliente[number(bpws:getVariableData("variable1"))]/ns4:codigo'/>
                      <to variable="Approved_Write_input" part="body"
                          query="/ns7:clientes/ns7:cliente/ns7:id"/>
                    </copy>
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query="/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:nombre"/>
                      <to variable="Approved_Write_input" part="body"
                          query="/ns7:clientes/ns7:cliente/ns7:nombre"/>
                    </copy>
                    <copy>
                      <from expression="sum(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:productos/ns4:producto/ns4:precio'))"/>
                      <to variable="Approved_Write_input" part="body"
                          query="/ns7:clientes/ns7:cliente/ns7:total"/>
                    </copy>
                  </assign>
                  <invoke name="Invoke2" inputVariable="Approved_Write_input"
                          partnerLink="fileAdapterWriteApproved"
                          portType="ns6:Write_ptt" operation="Write"
                          bpelx:invokeAsDetail="no"/>
                </sequence>
              </case>
              <otherwise>
                <sequence name="Sequence1">
                  <assign name="Assign5">
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query='/ns4:clientes/ns4:cliente[number(bpws:getVariableData("variable1"))]/ns4:codigo'/>
                      <to variable="Rechazados_Write_input" part="body"
                          query="/ns9:clientes/ns9:cliente/ns9:id"/>
                    </copy>
                    <copy>
                      <from variable="Receive1_input_files" part="body"
                            query="/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:nombre"/>
                      <to variable="Rechazados_Write_input" part="body"
                          query="/ns9:clientes/ns9:cliente/ns9:nombre"/>
                    </copy>
                    <copy>
                      <from expression="sum(bpws:getVariableData('Receive1_input_files','body','/ns4:clientes/ns4:cliente[number(bpws:getVariableData(&quot;variable1&quot;))]/ns4:productos/ns4:producto/ns4:precio'))"/>
                      <to variable="Rechazados_Write_input" part="body"
                          query="/ns9:clientes/ns9:cliente/ns9:total"/>
                    </copy>
                  </assign>
                  <invoke name="Invoke3"
                          inputVariable="Rechazados_Write_input"
                          partnerLink="fileAdapterWriteRechazados"
                          portType="ns8:Write_ptt" operation="Write"
                          bpelx:invokeAsDetail="no"/>
                </sequence>
              </otherwise>
            </switch>
            <assign name="Assign2">
              <copy>
                <from expression="''"/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:id"/>
              </copy>
              <copy>
                <from expression="bpws:getVariableData('variable1')+1"/>
                <to variable="variable1"/>
              </copy>
              <copy>
                <from expression="''"/>
                <to variable="Invoke1_process_InputVariable" part="payload"
                    query="/ns5:process/ns5:cantidad"/>
              </copy>
            </assign>
          </sequence>
        </while>

  • How many elements in an array?

    Sounds like a simple question, right?
    Apparently not.
    LV 2010
    I have a huge data structure, stored in DataLog files (thousands of them).
    I want to convert this structure to Name/Value pairs ("Operator_Name", "Joe Smith"), for use in a TDMS file.
    The structure is a cluster, with various clusters inside that, and inside those are DBLs, strings, BOOLs, other clusters, arrays, you name it.
    My strategy is to obtain the CONTROLS[ ] property of the outermost cluster and call this VI.
    The VI processes each control, decoding what type it is and handling it accordingly.
    It works fine for STRINGs, NUMERICs, ENUMs, BOOLEANs, COMBOBOXes, TIMESTAMPS, and CLUSTERs.
    For those simple ones, I use the LABEL.TEXT as the NAME and get the value (based on what type it is) as the VALUE.
    For a CLUSTER, I get the CONTROLS[ ] array of the cluster and call myself recursively, to handle all the elements within the sub-cluster.
    That all works fine.
    But to handle an ARRAY, I'm stumped.
    Attached is the code showing the case for an ARRAY.
    What I'm doing is getting the CLASS NAME of the current control.
    I LEGALIZE the label name (turn spaces into underscores, and maybe other special handling later).
    For an ARRAY, I cast the generic CTL reference into an ARRAY reference, and get its VALUE.
    I want to loop over each element of the array, and modify the name by the index number, and process each element.
    There are arrays of STRINGS, arrays of DBLs, arrays of CLUSTERs - all types.
    The question is - how many array elements are there?
    The constant "10" in this diagram is a dummy - just there to see if it works.
    it does work, except that I get 10 sets of answers, whether the real array has 2 or 20 elements.
    I thought the array's VALUE would be an ARRAY of VARIANTs, but no - it's a single VARIANT.
    I can't use VARIANT to DATA on the array's VALUE - I don't know what TYPE the array is.
    I thought maybe the ARRELEM refnum would be NIL if I was past the end, but that's not the case - there's only one refnum for any array element, whether it exists or not.
    If I check for errors, it complains that I cannot set the INDEXVALS property of a strict typedef array, even though it works just fine.
    If there was a method to SELECT ALL on the array, I could use the SELECTION SIZE to figure out how many elements there are, but I see no such method.
    The NUMBER OF ROWS / COLUMNS refers to the number of VISIBLE rows/columns, and has nothing to do with how much data is present.
    So... How do I find out how many elements are in the array?
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

    The ArrElem reference property is not a reference to any particular element of the array. 
    On the contrary, it is a reference to the element addressed by the current ARRAY INDEX(es).
    That's why my code above can read out the values for element 0, element 1, etc.  I've verified that this works.
    There is only one set of PROPERTIES for the array elements; if you use the ArrElem refnum to set a background color of blue, then ALL elements turn blue, but you can obtain the VALUE of a given element by setting the ARRAY INDEX(es) and accessing via the ArrElem.
    I was thinking that maybe LabVIEW did a trick by setting this to NIL to indicate "no such element", but that's not the case.
    In any case, the question remains: How do I determine how many elements there are?
    The VALUE of the array is a variant: just what is in that package?
    As I said, I don't see how to use VARIANT TO DATA; I don't know what kind of data it is.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Deleteing element by element in 2D array

    Is there away to delete element by element in 2D array without changing the dimensions to 1D array. I want to select the first 20 element reading across the rows. For example, If I have 2D array with 6 element in each raw. I want to select the first three rows and 2 elements from the four raw.
    Regards
    Hussain

    Maybe I completely misunderstand what the OP tried to say / do, but you can accomplish it without using clusters.  Comments from others are correct, you cannot resize the 2D array by deleting elements within a given row..  However, maybe you want to achieve what is described below.
    Do keep in mind that if you attempt this with a numeric array, you may want to use 0 or 'NaN' as your deleted value.
    See code below which should be self-explanatory.  There are probably better improvements of the example, but the purpose was simply to show how it can be done.
    Array 1 shows the original 2D array and it's values.
    Array 2 shows how you can "delete" or replace its element with a "deleted" value.
    Array 3 shows how you can "delete" multiple elements (replace multiple elements with a "deleted" value).
    Attachments:
    deleting inside 2D array.png ‏32 KB
    delInside2Darray.png ‏29 KB

  • Accessing form elements within a Spry region.

    Since nested Spry regions isn't yet support, can someone tell
    me how to access and modify form elements within a existing region?
    For example, I have a region that displays a form based on
    data I defined in a javascript array. On of the form elements is a
    select with some options. I want to added and remove options to
    this select depending on the number of objects in the data array.
    The select is not defined when I try to access it after spry
    has finished rendering the form, eg
    document.forms[0].selOrder1.options.length = 0;
    How are Spry regions attached to the browser's DOM? Does Spry
    create it's own DOM subordinate to the main DOM?
    Is it possible to make changes to a Spry region without using
    Spry?
    thx
    pwp

    Actually, there are a couple of ways to get access to the DOM
    underneath a region container. If you have a region, you can put an
    ID attribute on the region container node, or if you are using a
    region observer, the data passed into the observer has a regionNode
    property. So if you want access to the region DOM anytime the
    region is re-generated, do something like this:
    function myRegionObserver(notificationType, notifier, data)
    // We only want to do something after the region is
    re-generated,
    // for all other notifications, do nothing.
    if (notificationType != "onPostUpdate")
    return;
    // If your region container element has an ID on it, just
    use
    // getElementByID. This is useful in the case where your
    observer
    // is only ever registered with one region.
    var rgnElement1 = document.getElementById("headerRegion");
    alert(rgnElement1.innerHTML);
    // Or you can simply use the regionNode property of the data
    // that is passed in. This is useful if you've registered
    the same
    // observer on multiple regions. The regionNode property
    will
    // contain the region container node for the region that is
    currently
    // being updated.
    var rgnElement2 = data.regionNode;
    alert(rgnElement2.innerHTML);
    Spry.Data.Region.addObserver("headerRegion",
    myRegionObserver);
    <div id="headerRegion" spry:region="ds1">
    </div>
    --== Kin ==--

  • Shifting elements in multidementional array

    Hello,
    I'm working on a boardgame project which uses an int[][] to represent the board. The elements in this array are numbers which represent vehicles. The equal numbers are one vehicle. A vehicle can perform a step left/right, or a step up/down (if there is no other vehicle blocking the way of course).
    I've read about the arraycopy method, but I don't know how to use it with an array of arrays.
    So an example of the matrix would look like this:
    111002
    300502
    344502
    300500
    000000
    666000
    After a step of one vehicle the matrix could be:
    011102
    300502
    344502
    300500
    000000
    666000
    I need to get matrices for all possible moves, for all vehicles.
    I couldn't find any documentation about the use of copyarray with an array of arrays. Hope someone can point me in the right direction.
    Thanks in advance

    Ceylor wrote:
    Hello all,
    thanks very much for the quick replies.
    prometheuzz, I've read the topic you mentioned and your explanation is great. Your UML makes it very clear.You're welcome.
    I allready use OOP as much as possible. In my project I use a playField class (the board, also GUI), a node class (extends from rectangle, a cell in the field), a vehicle class (contains a collection of nodes and some other properties), a class for my algoritm and a state class.Good to hear that.
    The state class is used for storing all possible states of the playField. (ie all valid moves). These states are needed for a shortest path algoritm, and are not automatically a state the playField gets. Therefor I can't use the vehicles stored in the playField class because this class only contains the initial state of the game. The playField only get's updated when the algoritm is done and a shortest path is found. So would it be a good solution to store a collection of vehicles inside my state class?I'm don't quite follow you here, I'm afraid.
    The thing I'm a bit worried about is that there can be a lot of states. When adding the vehicles to each state object, doesn't this slow things down?
    ...Don't worry about inefficient code too soon. First get your logic correct: check your algorithm against a small puzzle, ensure that it works. After that, try some larger puzzles to see if a solution is found within the required time frame. If it takes too long, only then adjust your algorithm.
    Feel free to post back if you have any questions.
    Good luck.

  • Sorting a 2-D array

    Hello Every one,
                            Can any one please help me out in sorting a 2-D array. Here is the requirement there will be some groups, and each group consists of 'x' number of elements.The user enters only elements but in a zig zag order. And the program short sort out each channel and list out to which group it is belonging (Where the 2-D array of Group name and elements is provided).
    Say for example if there are three groups with some elements in each groups as follows.
    Physics: retarder, force,torque,capacity
    Chemistry: reaction, chemicals, sodium
    Geography: land,map,soil, earth.
    And if the user enters the following input's: soil, torque, chemical, force,reaction, land.
    The program should return the following output:
    Note : The order of the elements should match the order they are defined.
    Physics, force,torque                                    ------------ group name and group elements in the first row
    Chemistry, reaction, chemical                        ------------ group name and group elements in the Second row
    Geography,land, soil                                    ------------ group name and group elements in the third row
    Thanks for the help
    - Raghu
    Solved!
    Go to Solution.

    Sure Jim, I can definitely share my project details.Here is what we are trying to achieve.
    The attached vi is used to transmit the messages to Engine ECM. It takes the input's *.dbc file where the channel names are defined
    The present vi is working like this. It transmit messages correctly only if the messages are defined in the ascending order(the order in which they are defined in the *.dbc file).
    Say for example take 3 PGNS
    1) 18ff0fef Which has the following channels in the PGN
    a) Notch
    b) Gear
    c) Service brake
    2) 14ff2ef which has the following channels in the PGN
    a) Bus_voltage
    b) Bus_current
    c) power
    3)14ff03ef which has the following channels in the PGN
    a) Coolant_temp
    b) oil_press
    c) Imat
    If I want to transmit the following channels and define them in the following order
    1) Gear
    2) Imat
    3) Bus_voltage
    4) Notch
    The program is only writing correct data for Gear,Imat and some garbage values for Bus_voltage and Notch.
    But if I define the channels in the ascending order as defined in the *.dbc file in the following fashion
    1)Notch
    2)Gear
    3)Bus_voltage
    4)Imat
    I can transmit the right data for each channel.
    So what Iam trying to do is Iam planning to sort out all the channels names what user enter's and sort the channels in the  order as defined in the *.dbc file and pass it to the program.
    And the other issue I am facing is if two channels belong to the same PGN like Gear and Notch I have to transmit the values in the same array.
    Say for example i want to transmit the values as follows Notch =4; Gear = 3; Bus_voltage = 25; Imat = 80 the array matrix will be like this
    Array_1: 4,3
    Array_2: 25
    Array_3: 80.
    I was able to sort out all the channels listed in the *.dbc file in to single array but have no clue how to do the rest of work. Can you please help me in achieving the expected result. Iam attaching the vi and picture which describes where channel information and channel values are passed to the program.
    Thank you,
    - Raghu
    Attachments:
    Output.vi ‏27 KB
    TX_GUI.PNG ‏77 KB

  • How to sort a 2 dim. array by the first column?

    Hi there,
    I need to know, how to sort a 2 dim. String array by the first column, which means "string[0][x]".
    I think, I have to implement a new comparator class. But how?
    Thanks in advance for any help

    I need to know, how to sort a 2 dim. String
    array by the first column, which means
    "string[0][x]".You want to sort the array using the first element in each row and that element is a String?
    Let's forget about generics. Say you want to supply a Comparator. The compare method should decide the order between elements when passed two element objects. In a two-dimensional array the elements will be one-dimentional arrays and you use the first element in those arrays, like
    public int compare(Object s1, Object s2) {
       String[] a1 = (String[]) s1;  // first row array
       String[] a2 = (String[]) s2;  // second row array
       return a1[0].compareTo(a2[0]); // compare first element of row arrays
    }

  • Sorting a two-dimensional array to check min and max random results.

    I am working on a new project to learn more advanced uses of java, and have run into some very confusing output. the program should roll 2 6 sided dice 36000 times, storing the results (how many times each of the 21 possible combinations of rolls occurred) in a 2-d array, printing that array in tabular format, then copying the values to a 1d array to sort numericallly (ascending) then print which combination of rolls occured least and most, with how many occurences for each (least and most) here is the code I have, the error will be below it.
    package d12;
    //import classes to use
    import java.util.Random;
    import java.util.Arrays;
    public class randomDice2D {
         * @param args the command line arguments
        public static void main(String[] args) {
    //bring in new Random object
            Random r = new Random();
    //declare all variables and arrays
            int[][] dieResults; dieResults = new int[6][6];
            int[] sortingResults; sortingResults=new int[37];
            int one;  int two;  int three;  int four;  int five;  int six;
            int seven;  int eight;  int nine;  int ten;  int eleven;  int twelve;
            int thirteen;  int fourteen;  int fifteen;  int sixteen;  int seventeen;
            int eighteen;  int nineteen;  int twenty;  int twentyone;
            //initialize all variables at 0
            one=0;  two=0;  three=0;  four=0;  five=0;  six=0;  seven=0;  eight=0;
            nine=0;  ten=0;  eleven=0;  twelve=0;  thirteen=0;  fourteen=0;
            fifteen=0;  sixteen=0;  seventeen=0;  eighteen=0;  nineteen=0;
            twenty=0;  twentyone=0;
    //do dice rolling and count each iteration of each possible result - 36 possible??
            for (int i = 0; i < 36000; i++)
              int roll  = (r.nextInt(6) + 1) ;
              int roll2 = (r.nextInt(6) + 1) ;
            if (roll ==1 && roll2 == 1) ++one;
            if ((roll == 1 && roll2 == 2) || (roll2 == 1 && roll == 2)) ++two;
            if ((roll == 1 && roll2 == 3) || (roll2 == 1 && roll == 3)) ++three;
            if ((roll == 1 && roll2 == 4) || (roll2 == 1 && roll == 4)) ++four;
            if ((roll == 1 && roll2 == 5) || (roll2 == 1 && roll == 5)) ++five;
            if ((roll == 1 && roll2 == 6) || (roll2 == 1 && roll == 6)) ++six;
            if (roll == 2 && roll2 == 2) ++seven;
            if ((roll == 2 && roll2 == 3) || (roll2 == 2 && roll == 3)) ++eight;
            if ((roll == 2 && roll2 == 4) || (roll2 == 2 && roll == 4)) ++nine;
            if ((roll == 2 && roll2 == 5) || (roll2 == 2 && roll == 5)) ++ten;
            if ((roll == 2 && roll2 == 6) || (roll2 == 2 && roll == 6)) ++eleven;
            if ((roll == 3 && roll2 == 3)) ++twelve;
            if ((roll == 3 && roll2 == 4) || (roll2 == 3 && roll == 4)) ++thirteen;
            if ((roll == 3 && roll2 == 5) || (roll2 == 3 && roll == 5)) ++fourteen;
            if ((roll == 3 && roll2 == 6) || (roll2 == 3 && roll == 6)) ++fifteen;
            if (roll == 4 && roll2 == 4) ++sixteen;
            if ((roll == 4 && roll2 == 5) || (roll2 == 4 && roll == 5)) ++seventeen;
            if ((roll == 4 && roll2 == 6) || (roll2 == 4 && roll == 6)) ++eighteen;
            if (roll == 5 && roll2 == 5) ++nineteen;
            if ((roll == 5 && roll2 == 6) || (roll2 == 5 && roll == 6)) ++twenty;
            if (roll == 6 && roll2 == 6) ++twentyone;
            //assign results to array
            dieResults[0][0]=one;
            dieResults[1][0]=two; dieResults[0][1]=two;
            dieResults[2][0]=three;dieResults[0][2]=three;
            dieResults[3][0]=four;dieResults[0][3]=four;
            dieResults[4][0]=five;dieResults[0][4]=five;
            dieResults[5][0]=six;dieResults[0][5]=six;
            dieResults[1][1]=seven;
            dieResults[2][1]=eight;dieResults[1][2]=eight;dieResults[3][1]=nine;
            dieResults[1][3]=nine;dieResults[4][1]=ten;dieResults[1][4]=ten;
            dieResults[5][1]=eleven;dieResults[1][5]=eleven;
            dieResults[2][2]=twelve;
            dieResults[3][2]=thirteen;dieResults[2][3]=thirteen;
            dieResults[4][2]=fourteen;dieResults[2][4]=fourteen;
            dieResults[5][2]=fifteen;dieResults[2][5]=fifteen;
            dieResults[3][3]=sixteen;
            dieResults[4][3]=seventeen;dieResults[3][4]=seventeen;
            dieResults[5][3]=eighteen;dieResults[3][5]=eighteen;
            dieResults[4][4]=nineteen;
            dieResults[5][4]=twenty;dieResults[4][5]=twenty;
            dieResults[5][5]=twentyone;
            //print results
            for (int j=0; j<dieResults.length; j++){
                System.out.print("\n");
                for (int k=0; k<dieResults.length; k++){
                System.out.print("|"+dieResults[j][k]+"| ");
            // Verify program accuracy and ensure total reported results add up to 36000
    System.out.println("\nValidate: 1's; "+dieResults[0][0]+" 1 & 2; "+dieResults[1][0]+
            dieResults[0][1]+" 4's; "+dieResults[2][0]+dieResults[0][2]+" 5's; "
            +dieResults[3][0]+dieResults[0][3]+" 6's; "+dieResults[4][0]+dieResults[0][4]
            +" 7's; "+dieResults[5][0]+dieResults[0][5]);
    System.out.println("All total rolls add up to " + (dieResults[0][0] + dieResults[0][1] +
             dieResults[0][2] + dieResults[0][3] + dieResults[0][4] + dieResults[0][5]));
    //check lowest/highest numbers entered to verify results are reasonable
    //sort results to obtain lowest and highest number of rolls
        for (int l=0; l<sortingResults.length;l++){
         for (int m=0; m<sortingResults.length;m++){
            sortingResults[l]=dieResults[l][m];
    Arrays.sort(sortingResults);
    //determine and print what roll occurred the least
        if (sortingResults[0] == two)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2's with " + sortingResults[0]);
        if (sortingResults[0] == three)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3's with " + sortingResults[0]);
        if (sortingResults[0] == four)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4's with " + sortingResults[0]);
        if (sortingResults[0] == five)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5's with " + sortingResults[0]);
        if (sortingResults[0] == six)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6's with " + sortingResults[0]);
        if (sortingResults[0] == seven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "7's with " + sortingResults[0]);
        if (sortingResults[0] == eight)
            System.out.println("The lowest number of rolls for a single result is "
                    + "8's with " + sortingResults[0]);
        if (sortingResults[0] == nine)
            System.out.println("The lowest number of rolls for a single result is "
                    + "9's with " + sortingResults[0]);
        if (sortingResults[0] == ten)
            System.out.println("The lowest number of rolls for a single result is "
                    + "10's with " + sortingResults[0]);
        if (sortingResults[0] == eleven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "11's with " + sortingResults[0]);
        if (sortingResults[0] == twelve)
            System.out.println("The lowest number of rolls for a single result is "
                    + "12's with " + sortingResults[0]);
    //determine and print what roll occurred the most
        if (dieResults[5][5] == two)
            System.out.println("The highest number of rolls for a single result is "
                    + "2's with " + dieResults[10]);
        if (dieResults[5][5] == three)
            System.out.println("The highest number of rolls for a single result is "
                    + "3's with " + dieResults[10]);
        if (dieResults[5][5] == four)
            System.out.println("The highest number of rolls for a single result is "
                    + "4's with " + dieResults[10]);
        if (dieResults[5][5] == five)
            System.out.println("The highest number of rolls for a single result is "
                    + "5's with " + dieResults[10]);
        if (dieResults[5][5] == six)
            System.out.println("The highest number of rolls for a single result is "
                    + "6's with " + dieResults[10]);
        if (dieResults[5][5] == seven)
            System.out.println("The highest number of rolls for a single result is "
                    + "7's with " + dieResults[10]);
        if (dieResults[5][5] == eight)
            System.out.println("The highest number of rolls for a single result is "
                    + "8's with " + dieResults[10]);
        if (dieResults[5][5] == nine)
            System.out.println("The highest number of rolls for a single result is "
                    + "9's with " + dieResults[10]);
        if (dieResults[5][5] == ten)
            System.out.println("The lohighestwest number of rolls for a single result is "
                    + "10's with " + dieResults[10]);
        if (dieResults[5][5] == eleven)
            System.out.println("The highest number of rolls for a single result is "
                    + "11's with " + dieResults[10]);
        if (dieResults[5][5] == twelve)
            System.out.println("The highest number of rolls for a single result is "
                    + "12's with " + dieResults[10]);
    }the output I got was this:
    run:
    |988| |2038| |1933| |2008| |2095| |2002|
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
    |2038| |965| |1973| |1982| |1985| |2028|
    |1933| |1973| |1034| |1952| |1928| |2055|
    |2008| |1982| |1952| |1010| |1981| |2023|
    |2095| |1985| |1928| |1981| |1041| |1996|
    |2002| |2028| |2055| |2023| |1996| |983| Validate: 1's; 988 1 & 2; 20382038 4's; 19331933 5's; 20082008 6's; 20952095 7's; 20022002
    All total rolls add up to 11064
            at d12.randomDice2D.main(randomDice2D.java:101)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)I can see from the validate line in output that i need to start that line with a \n and change the formula of that println from
    +dieResults[x][y]+dieResults[y][x]+
    to
    +(dieResults[x][y]+dieResults[y][x])+
    I am also aware i have to finish listing all the elements of the array to add to the all total rolls line, but that I can add as I wait for an answer to the errors I don't see the solutions to. The last thing I need help with is how to print those results in a 2-d table format instead of one number per line. Should I change the pair of loops here:
    for (int l=0; l<sortingResults.length;l++){
         for (int m=0; m<sortingResults.length;m++){
            sortingResults[l]=dieResults[l][m];
            }    }to a single loop repeated till the end like this?
    for (int l=0; l<6; l++){
    sortingResults[l]=dieResults[l][0];}
    for (int m=0; m<5; m++){
    sortingResults[(m+6)]=dieResults[m][1];}
    for (int n=0; n<4; n++){
    sortingResults[(n+11)]=dieResults[n][1];}or just take 21 lines (or 36 if i track all results instead of all unique) to declare each element like:
    sortingResults[a]=dieResults[x][y];
    Edited by: Geode on Oct 20, 2010 12:38 AM

    Ok, I have done a lot and thought I had worked out all of the problems. Netbeans had no problems compiling it or running it, and the output was exactly what I expected it to be. Then I decided that the println starting "Validate:" was unneccessary since I printed the table right before it, so I deleted it. Noww Netbeans is telling me it compiles with errors every time i run it, even though it doesn't flag any line as having an error and it still executes exactly as I expect it to. Also, I was not able to find a way to make the three big sets of if's into loops. Any suggestions or ideas on how they could be looped would be most welcome. Also, any ideas on why Netbeans is saying it compiles with errors when it does not give any. I'll give the code and then the output again.
    package d12;
    //import classes to use
    import java.util.Random;
    import java.util.Arrays;
    public class randomDice2D {
         * @param args the command line arguments
        public static void main(String[] args) {
    //bring in new Random object
            Random r = new Random();
    //declare all variables and arrays
            int[][] dieResults; dieResults = new int[6][6];
            int[] sortingResults; sortingResults=new int[36];
            int one; int two; int three; int four; int five; int six; int seven;
            int eight; int nine; int ten; int eleven; int twelve; int thirteen;
            int fourteen; int fifteen; int sixteen; int seventeen; int eighteen;
            int nineteen; int twenty; int twentyone; int twentytwo; int twentythree;
            int twentyfour; int twentyfive; int twentysix; int twentyseven;
            int twentyeight; int twentynine; int thirty; int thirtyone; int thirtytwo;
            int thirtythree; int thirtyfour; int thirtyfive; int thirtysix;
            //initialize all variables at 0
            one=0;two=0;three=0;four=0;five=0;six=0;seven=0;eight=0;nine=0;ten=0;
            eleven=0;twelve=0;thirteen=0;fourteen=0;fifteen=0;sixteen=0;seventeen=0;
            eighteen=0;nineteen=0;twenty=0;twentyone=0;twentytwo=0;twentythree=0;
            twentyfour=0;twentyfive=0;twentysix=0;twentyseven=0;twentyeight=0;
            twentynine=0;thirty=0;thirtyone=0;thirtytwo=0;thirtythree=0;thirtyfour=0;
            thirtyfive=0;thirtysix=0;
    //do dice rolling and count each iteration of each possible result - 36 possible??
            for (int i = 0; i < 36000; i++)
              int roll  = (r.nextInt(6) + 1) ;
              int roll2 = (r.nextInt(6) + 1) ;
            if (roll == 1 && roll2 == 1) ++one;
            if (roll == 1 && roll2 == 2) ++two;
            if (roll == 1 && roll2 == 3) ++three;
            if (roll == 1 && roll2 == 4) ++four;
            if (roll == 1 && roll2 == 5) ++five;
            if (roll == 1 && roll2 == 6) ++six;
            if (roll == 2 && roll2 == 1) ++seven;
            if (roll == 2 && roll2 == 2) ++eight;
            if (roll == 2 && roll2 == 3) ++nine;
            if (roll == 2 && roll2 == 4) ++ten;
            if (roll == 2 && roll2 == 5) ++eleven;
            if (roll == 2 && roll2 == 6) ++twelve;
            if (roll == 3 && roll2 == 1) ++thirteen;
            if (roll == 3 && roll2 == 2) ++fourteen;
            if (roll == 3 && roll2 == 3) ++fifteen;
            if (roll == 3 && roll2 == 4) ++sixteen;
            if (roll == 3 && roll2 == 5) ++seventeen;
            if (roll == 3 && roll2 == 6) ++eighteen;
            if (roll == 4 && roll2 == 1) ++nineteen;
            if (roll == 4 && roll2 == 2) ++twenty;
            if (roll == 4 && roll2 == 3) ++twentyone;
            if (roll == 4 && roll2 == 4) ++twentytwo;
            if (roll == 4 && roll2 == 5) ++twentythree;
            if (roll == 4 && roll2 == 6) ++twentyfour;
            if (roll == 5 && roll2 == 1) ++twentyfive;
            if (roll == 5 && roll2 == 2) ++twentysix;
            if (roll == 5 && roll2 == 3) ++twentyseven;
            if (roll == 5 && roll2 == 4) ++twentyeight;
            if (roll == 5 && roll2 == 5) ++twentynine;
            if (roll == 5 && roll2 == 6) ++thirty;
            if (roll == 6 && roll2 == 1) ++thirtyone;
            if (roll == 6 && roll2 == 2) ++thirtytwo;
            if (roll == 6 && roll2 == 3) ++thirtythree;
            if (roll == 6 && roll2 == 4) ++thirtyfour;
            if (roll == 6 && roll2 == 5) ++thirtyfive;
            if (roll == 6 && roll2 == 6) ++thirtysix;
            //assign results to array
            dieResults[0][0]=one;dieResults[1][0]=seven; dieResults[0][1]=two;
            dieResults[2][0]=thirteen;dieResults[0][2]=three;dieResults[3][0]=nineteen;
            dieResults[0][3]=four;dieResults[4][0]=twentyfive;dieResults[0][4]=five;
            dieResults[5][0]=thirtyone;dieResults[0][5]=six;dieResults[1][1]=eight;
            dieResults[2][1]=fourteen;dieResults[1][2]=nine;dieResults[3][1]=twenty;
            dieResults[1][3]=ten;dieResults[4][1]=twentysix;dieResults[1][4]=eleven;
            dieResults[5][1]=thirtytwo;dieResults[1][5]=twelve;dieResults[2][2]=fifteen;
            dieResults[3][2]=twentyone;dieResults[2][3]=sixteen;dieResults[4][2]=twentyseven;
            dieResults[2][4]=seventeen;dieResults[5][2]=thirtythree;dieResults[2][5]=eighteen;
            dieResults[3][3]=twentytwo;dieResults[4][3]=twentyeight;dieResults[3][4]=twentythree;
            dieResults[5][3]=thirtyfour;dieResults[3][5]=twentyfour;dieResults[4][4]=twentynine;
            dieResults[5][4]=thirtyfive;dieResults[4][5]=thirty;dieResults[5][5]=thirtysix;
            //print results
            System.out.println("     1      2      3      4     5      6");
            for (int j=0; j<dieResults.length; j++){
                System.out.print("\n"+(j+1)+" -");
                for (int k=0; k<dieResults.length; k++){
                System.out.print("|"+dieResults[j][k]+"| ");
            // Verify program accuracy to ensure total results add up to 36000
    System.out.println("\nAll total rolls add up to "+(dieResults[0][0]+dieResults[0][1]+
             dieResults[0][2]+dieResults[0][3]+dieResults[0][4]+dieResults[0][5]+
             dieResults[1][0]+dieResults[1][1]+dieResults[1][2]+dieResults[1][3]+
             dieResults[1][4]+dieResults[1][5]+dieResults[2][0]+dieResults[2][1]+
             dieResults[2][2]+dieResults[2][3]+dieResults[2][4]+dieResults[2][5]+
             dieResults[3][0]+dieResults[3][1]+dieResults[3][2]+dieResults[3][3]+
             dieResults[3][4]+dieResults[3][5]+dieResults[4][0]+dieResults[4][1]+
             dieResults[4][2]+dieResults[4][3]+dieResults[4][4]+dieResults[4][5]+
             dieResults[5][0]+dieResults[5][1]+dieResults[5][2]+dieResults[5][3]+
             dieResults[5][4]+dieResults[5][5]));
    //check lowest/highest numbers entered to verify results are reasonable
    //sort results to obtain lowest and highest number of rolls 
    int z;z=0;
    while (z < 36){
    for (int l=0; l<6;l++){
         for (int m=0; m<6;m++){
            sortingResults[z]=dieResults[l][m];++z;
    Arrays.sort(sortingResults);
    //determine and print what roll occurred the least
        if (sortingResults[0] == one)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1's with " + sortingResults[0]);
        if (sortingResults[0] == two)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == three)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == four)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == five)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == six)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == seven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == eight)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == nine)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == ten)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == eleven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == twelve)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == thirteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == fourteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == fifteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == sixteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == seventeen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == eighteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == nineteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == twenty)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == twentyone)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == twentytwo)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == twentythree)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == twentyfour)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == twentyfive)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == twentysix)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == twentyseven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == twentyeight)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == twentynine)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == thirty)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == thirtyone)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == thirtytwo)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == thirtythree)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == thirtyfour)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == thirtyfive)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == thirtysix)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 6 with " + sortingResults[0]);
    //determine and print what roll occurred the most
        if (sortingResults[35] == one)
            System.out.println("The highest number of rolls for a single result is "
                    + "1's with " + sortingResults[35]);
        if (sortingResults[35] == two)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == three)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == four)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == five)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == six)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == seven)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == eight)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == nine)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == ten)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == eleven)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == twelve)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == thirteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == fourteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == fifteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == sixteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == seventeen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == eighteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == nineteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == twenty)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == twentyone)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == twentytwo)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == twentythree)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == twentyfour)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == twentyfive)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == twentysix)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == twentyseven)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == twentyeight)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == twentynine)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == thirty)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == thirtyone)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == thirtytwo)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == thirtythree)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == thirtyfour)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == thirtyfive)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == thirtysix)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 6 with " + sortingResults[35]);
    }and here is the output (after clicking 'Run Anyways' on the project compiled with errors message from Netbeans)
    run:
         1      2      3      4     5      6
    1 -|995| |1014| |1076| |976| |1015| |1000|
    2 -|971| |982| |993| |1067| |983| |1011|
    3 -|990| |951| |1019| |968| |1011| |1023|
    4 -|999| |931| |1009| |987| |1020| |1022|
    5 -|969| |954| |997| |970| |1016| |1028|
    6 -|955| |1014| |996| |996| |1075| |1017|
    All total rolls add up to 36000
    The lowest number of rolls for a single result is 4 & 2 with 931
    The highest number of rolls for a single result is 1 & 3 with 1076
    BUILD SUCCESSFUL (total time: 13 seconds)

  • Converting a single entry within an array into 16 entries within a new array. Building an array without knowing the exact amount of array entries.

    I'm developing a VI that reads a text file and does a manipulation on the data it reads. The VI does the following: First, it reads all the ASCII characters from a text file, converts them to 8-bit words, until EOF occurs. Then I do some simple conversion to each byte. The result is that each bit entry of the byte now gives 2 3-bit entries, making a total of 16 3-bit values returned for each byte within the original array. For example, when I read element #0 of the byte array, I get the byte value of 1011000. My VI then converts this to 16 seperate 3-bit values. I can do the conversion just fine. My pro
    blem is figuring out how to put these 16 elements into an array to be written out of my 6534 card. I know how to do the DIO write part, but the problem is how do I combine the 16 elements into an array for thousands of bytes read from the text file? Also, the size of the file that I read is unknown until it is read, so I may have to output many sucessive outputs as described above. The first element read would give 16 3-bit elements for the new array, the second byte read would give another 16 3-bit elements and so on upto N values in the original array. Any ideas ?

    Place a for loop, wire N with your readed string lenght, pass the string inside and wire it to string subset, with the lenght entry wired to 1 and the offset entry to the loop counter (i). Then, you can play with every character inside the loop, and have an output array composed with the result of every character.
    Hope this helps

Maybe you are looking for

  • Calculated values: how to? Newbie question

    Hi, I have a view object with attributes X and Y (both numbers). How can I add a computed attribute (X*Y) ? I tried to - do "New" attribute in View Object wizard" - then set flag Queriable to false - remove that attribute from the SQL query - edit th

  • Cannot download album purchased yesterday

    I purchased an album yesterday, straight to my iPhone. When updating my iTunes on my PC last night, and syncing my phone the album was lost. The album is not on my phone or PC. When I go into purchases it is not in there. However when I search the al

  • Eccomerce / products into multiple catalogues

    i am building a eccomerce store. We sell vehicle accessories and a large percentage of our products will suit multiple vehicles. i will build a catalogue structure to place the products into but i would like each product that is relative to more than

  • I want to save some voice messages.

    I want to permanently save some voice messages from my phone. I've been looking for an answer as to how I'm going to be able to do this. I want them saved on a different media so I can erase them off my phone. The voice messages are proof for somethi

  • Syncing on ipad

    I try to download games onto the ipad, but a message comes up "file cannot be found, cannot continue syncing"