Array as instace variable

i wan to declare array as a instance variable.
i am below sample prog. , i get incorrect output.
is there any other way;
class a
     int m[];
     a(int ab[])
          m = new int[3];
          m = ab;
     void print()
          System.out.println(m[0]+" "+m[1]+" "+m[2]);
class test1
     public static void main(String args[])
          int score[] = new int[3];
          a group[] = new a[3];
          int flag=0;
          for (int k=0;k<3;k++)
               for(int i=0;i<3;i++)
                    if(flag==0)
                         score[i] = i+10;
                    else
                         score[i] = i+100;
               flag++;
               group[k] = new a(score);
               group[k].print();
          group[0].print(); // incorrect output as it prints last inputted value
}

// score[k] = i+10;
// it is not my problem, my problem is that the value of group[0] is not printed out of the loop. inside the for loop , its prints allright but outside the loop its get all wrong. i want to know that anything is wrong with class A structure.
class A
     int m[];
     A(int ab[])
          m = new int[3];
          m = ab;
     void print()
          System.out.println(m[0]+" "+m[1]+" "+m[2]);
class test1
     public static void main(String args[])
          int score[] = new int[3];
          A group[] = new A[3];
          int flag=0;
          for (int k=0;k<3;k++)
               for(int i=0;i<3;i++)
                    if(flag==0)
                    score[i] = i+10;                    else
                    score[i] = i+100;
               flag++;
               group[k] = new A(score);
               group[k].print();// print correct output
          group[0].print(); // prints value of group[2]
}

Similar Messages

  • How to create an array containing shared variable values

    Hi
    I am trying to programmatically create an array containing shared variable values and their names.  I can get the variable names by supplying the process name to the get shared variable list function.  How do I then read the value of all the shared variable items returned?
    I have used a data socket open to open a connection to all variables when my program starts.  I then use datasocket read on the opened connections to write to an array.  This works fine until I try to write to one of the variables using a shared variable node.  The variables writes can take from 4secs to 2 mins.  When I remove the shared variable node again all is fine.  Also when I stop using the data sockets, all is fine.
    Is there a conflict between shared variable nodes and data socket writes to the shared variables?
    Can anyone help?  I cannot easily post example code because I am reading the variables from a Wago PFC (PLC) using OPC.

    Hi
    Sorry I forgot to mention the LabVIEW version, its 8.20.  I have tried saving the shared variable node as a sub VI and it makes no difference.
    Attached is a stripped down version of the software.  You will not be able to connect to the IO server because it requires some Wago hardware and software.  You may spot something I have done wrong with the I/O servers, variables or sub VI's.
    The main program that runs is called 'HMI Engine' in the 'Framework' folder.  There may be some other things in the project that aren't used in this example.  I have removed all but the variable connection part of the code.
    I hope someone can help!?
    Thanks
    Mark.
    Attachments:
    HMI Test.zip ‏144 KB

  • Assigning java script array to a variable in struts form class

    Hi,
    I am trying to send a javascript array of string from jsp to struts action form.
    I have constructed a javascript array and assigned it to the form variable. But iam not able to access the variable in Action form. :( please let me know as to how i can send a string array in javascript to action form?.
    JavaScript
    var scriptarray = new Array();
    // code for populating the array
    document.MyForm.javaArray = scriptArray;
    document.MyForm.action="MyAction.do?dispatch=handlerMethod";
    document.MyForm.submit();

    var input = document.createElement("input");
    input.setAttribute("type", "hidden");
    input.setAttribute("name", "bla..bla");
    input.setAttribute("value", "bla..bla");And in addition to that.. Google is still alive

  • Problem in assigning script array to Js variable

    There is a huge list(20,000) of cities that has to be put into a script array for the further use in the jsp page. so this script array is created once for all when the login is made for the application and stored a session variable. The sample of the script array is like-----
    <script>
    strArrCityName[17463]= "Zoar";
    strArrCityID[17463]= "10599";
    strArrCityStateID[17463]= "3";
    strArrCityName[17464]= "Zoarville";
    strArrCityID[17464]= "10600";
    strArrCityStateID[17464]= "3";
    </script>
    the entire stuff from <script>---</script>(uncluding the script tags is stored as a string in the session (strSessionCityArr))
    Now the porblem is i need to store this array into a js variable on jsp page load.
    I order to that i need to declare a js variable in jsp page
    ex::
    <html>
    <body>
    This is a sample jsp page created by <%= strUserName%>
    <script>
    var cityarry = "<%=session.getAttribute('strSessionCityArr')%>";
    </script>
    </body>
    </html>
    when i assign the array to the js variable , the <script> tag inside the string is conflicting with the <script> tag that of the jsp page.
    This throws the js error and the futher loading of the page is stopped.
    The reason i am storing it in the js variable is i will be painting the script array dyanamically on click of a button.
    Also in need both the script tags in the array is in other jsp pages i will painting the array on page load by using the out.println(strCityArray)
    I need a way in which this script array can be stored in js variable or any method by which i can directly get it from the session on button click
    Thanx in advance
    Manu

    i had tired constructing the script array using the JS but JS logic is always slower ...my point was not to do it all with JS code. My point was that unless you know how to properly define it as JS-only code, then it makes it hard to figure out how to break that up to Java generated code. It's clear to me that you don't have a very good grasp of what you're trying to do.
    The second point is, in some JSPs i need the <script> tags to be included in the array. No they don't. You can always put the <script> tags around what your Java variable includes if you are using that content in several places...
    <script><%= session.getAttribute('strSessionCityArr') %></script>

  • Check Box values not reflecting in the pageflow instace variable

    Hello BEA Experts,
    I am binding a checkBox group to an instance variable of a Pageflow , it seems that the array inside the pageflow is null no matter what can you please let me know why.
    Is it possible to bind the checkbox group tag to an array in Pageflow or is there anything wrong with the way I am using the checkbox group with in a data- repeater table.
    Here are the code snippets..
    JSP:
    <netui-data:repeaterItem>
    <tr class="tablebody">
    <td>
    <netui:checkBoxGroup dataSource="{pageFlow.nodeIds}">
    <netui:checkBoxOption value="{container.item.nodeId}">&nbsp
    </netui:checkBoxOption>
    </netui:checkBoxGroup>
    Contoller:
    Has a private instance varible named nodeIds with getter and setter methods..
    Please let me know why the checked values are not reflecting in the pageFlow attribute.

    Hi Bob
    I didn't understand fully what you are trying here. Could you please clarify?
    I assume that you have a Array of NodeId objects.
    Lets say:
    Public NodeId[] nodeids = new NodeIds[10];
    and you want a checkBoxGroup mapped to NodeId[]
    and have as many checkBoxOption as number of elements in array with value as NodeId(i).nodeId
    Is this assumption correct?
    If the above is correct then the code snippet you have pasted is wrong in the sense that checkBoxGroup datasource is the array but the Option value is the main repeater item's nodeId which is wrong.
    The container.item would not access anything within the pageflow variable.
    I will post a sample in the next one
    Vimala-

  • Array of file variables

    I wanted to have an array of variables of type Text_IO.File_Type.
    So I declared:
    TYPE file_array IS VARRAY(20) of Text_IO.File_Type;
    f_array file_array;
    begin
         f_array(1) := Text_IO.Fopen('c:\file', 'w');
    This compiled but didn't work, the Fopen fails, all other Fopen's that are not with array variables worked.
    Any idea why?
    Thanks.
    --Bassem                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Your syntax is slightly wrong you must initialise and extend the array:
    declare
      TYPE file_array IS VARRAY(20) of Text_IO.File_Type;
      f_array file_array := file_array();
    begin
      f_array.extend;
      f_array(1) := Text_IO.Fopen('c:\file', 'w'); It will then work.

  • Can't create float array with a variable name as size parameter?

    Hi,
    When trying to compile code that users a variable in the array subscript to set the size, CC gives the following error:
    Error: An integer constant expression is required within the array subscript operator.
    1 Error(s) detected.The code is as follows:
    int main()
    //blah blah
    const int arrSize = numberVariables;
        float tempArr[arrSize];
    //blah blah
    }Output from CC -V:
    unknown% CC -V
    CC: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25Output from uname -a:
    unknown% uname -a
    SunOS unknown 5.10 Generic_137138-09 i86pc i386 i86pcAny ideas on why CC is giving that error?
    ~Slow
    Edited by: SlowToady on Nov 15, 2008 8:28 PM
    Edited by: SlowToady on Nov 15, 2008 8:36 PM

    Marc_Glisse wrote:
    Last time I checked, I did not see VLAs in the draft of the next C++ standard, which I believe is now feature complete. So either I missed it (quite possible) or VLAs were considered a bad idea (for C as well many people consider alloca and VLA bad ideas). It is however a very reasonable extension to have (care to file a RFE?).The following code performs like this on an IBM x366 with 4 single-core 3.16 GHz Xeons, running OpenSolaris build 96:
    -bash-3.2$ ./thrtest
    malloc() took 440895924 ns
    alloca() took 2122522 ns
    -bash-3.2$Using alloca is two hundred times faster.
    Two hundred times faster.
    Think about that next time some pedant says alloca "sucks".
    Try for yourself. Here's the code:
    #include <stdlib.h>
    #include <pthread.h>
    #include <alloca.h>
    #include <strings.h>
    #include <stdio.h>
    #define NUM_THREADS 8
    #define ITERS 10000
    #define BYTES 1024
    typedef void ( *mem_func_t )( void );
    void alloca_iter()
        char *ptr;
        ptr = ( char * ) alloca( BYTES );
        memset( ptr, 0, BYTES );
        return;
    void malloc_iter()
        char *ptr;
        ptr = ( char * ) malloc( BYTES );
        memset( ptr, 0, BYTES );
        free( ptr );
        return;
    void *thread_proc( void *arg )
        mem_func_t mem_iter;
        mem_iter = ( mem_func_t ) arg;
        for ( int ii = 0; ii < ITERS; ii++ )
            mem_iter();
        return( NULL );
    int main( int argc, char **argv )
        pthread_t tids[ NUM_THREADS ];
        void *results[ NUM_THREADS ];
        hrtime_t start;
        hrtime_t end;
        int ii;
        start = gethrtime();
        for ( ii = 0; ii < NUM_THREADS; ii++ )
            pthread_create( &tids[ ii ], NULL, thread_proc, malloc_iter );
        for ( ii = 0; ii < NUM_THREADS; ii++ )
            pthread_join( tids[ ii ], &results[ ii ] );
        end = gethrtime();
        printf( "malloc() took %ld ns\n", end - start );
        start = gethrtime();
        for ( ii = 0; ii < NUM_THREADS; ii++ )
            pthread_create( &tids[ ii ], NULL, thread_proc, alloca_iter );
        for ( ii = 0; ii < NUM_THREADS; ii++ )
            pthread_join( tids[ ii ], &results[ ii ] );
        end = gethrtime();
        printf( "alloca() took %ld ns\n", end - start );
        return( 0 );
    }

  • PL/SQL array bind output variable

    I've been trying to learn how to pass an array to an pl/sql script. Getting the data into the db seems to be working fine, but I would like to know if there was a problem inserting the data. More specifically, I would like to know THE SPECIFIC ROW that caused the problem.
    pl/sql code:
    create or replace procedure pp (
              v_out      out number,
              v_listtype in repair_codes.listtype%type,
    v_repaircode in repair_codes.repaircode%type
    is
    begin
    insert into repair_codes (listtype, repaircode) values (v_listtype,v_repaircode);
         v_out:=1;
    commit;
         --just setting up test variable for now     
    end;
    vb.code:
    Dim cmd As New OracleCommand("pp", dbConn)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.ArrayBindCount = 3
    Dim al(2) As String
    Dim ar(2) As String
    al(0) = "JOE1"
    al(1) = "JOE2"
    al(2) = "JOE3"
    ar(0) = "TEST1"
    ar(1) = "TEST2"
    ar(2) = "TEST3456789"
    Dim out As New OracleParameter("v_out", OracleDbType.Varchar2, 20)
    out.Direction = ParameterDirection.Output
    cmd.Parameters.Add(out)
    Dim listtype As New OracleParameter("v_listtype", OracleDbType.Varchar2)
    listtype.Value = al
    cmd.Parameters.Add(listtype)
    Dim repaircode As New OracleParameter("v_repaircode", OracleDbType.Varchar2)
    repaircode.Value = ar
    cmd.Parameters.Add(repaircode)
    dbConn.Open()
    Try
    cmd.ExecuteNonQuery()
    Catch ex As OracleException ' catches only Oracle errors
    ex = ex
    Select Case ex.Number
    Case 1
    MessageBox.Show("Error attempting to insert duplicate data.")
    Case 12545
    MessageBox.Show("The database is unavailable.")
    Case Else
    MessageBox.Show("Database error: " & ex.Message.ToString())
    Dim wha = ex.Errors(0).ArrayBindIndex 'always '0'
    End Select
    Finally
    dbConn.Close()
    End Try
    error:
    OracleParameter.ArrayBindSize is invalid
    Code above will work if I remove everything about the 'output' variable
    To test I would like to put in data for a column that is too large, have all other rows inserted, but return the row that had bad data. Thanks for any thoughts on this-

    I have a similar issue, i.e. the pl/sql table type as out parameter is causing probleml in one API related to Oracle Applications. I have singled this problem out by creating wrappers and testing them against BPEL process. Now as soon as I put an out parameter with pl/sql table in my wrapper, I start getting errors. Why the invoke even care about what is in output while calling the API? How can I get rid of it. I am not able to pin point where exactly you made the changes. Could you please share some more info or possibly share the BAD and GOOD code.
    We will probably get away with this by creating just a wrapper that would have NO out parameter as PL/SQL table as I don't think we need it anyway.
    Still want to know what is the issue here as we would like to avoid any custom wrapper creation?
    Shobhit
    Message was edited by:
    Shobhit.Kapila

  • Order array by object variable

    Hello !
    I have an array which I'm looping through to get variables(as text) to display in dynamic text fields..
    If possible I would like to sort the array into numeric order using "sTabArray[i].sHour". A variable of each of the array items..
    Is there a way I can do this ? Maybe create a new array from the original one and then use that ??
    for(i = 0; i < sTabArray.length; i++) {
        var sMin:String = sTabArray[i].sMin;
        var fMin:String = sTabArray[i].fMin;
        var table_number:String = sTabArray[i].table_number;
        var salle_number:String = sTabArray[i].salle_number;
        printBox["horaires" + i].text = sTabArray[i].sHour + ":" + sMin + " à " + sTabArray[i].fHour + ":" + fMin;
        printBox["evenement" + i].text = sTabArray[i].titre;
        printBox["salle" + i].text = salle_number;
        printBox["table_no" + i].text = table_number;
    Many thanks in advance for you help
    Martin

    sortOn
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#sortOn%28%29

  • Javascript array in global variables

    Hi,
    In my form, I created a global variable called MyArray. Then in my form's initialization script, I've set:
    myform.variables.MyArray = new Array(5);
    and I initialized each value.
    In one of my button's click event, I try to access my global array, without success. I tried:
    myform.variables.MyArray[0], myform.variables.MyArray.value[0]... has anyone managed to create a global variable and use it as an array?
    Thank you!

    Hello.
    I have used the "global." to get global variables. It works fine. I have code like this that works:
    // Initialize global array.
    global.chVArray = new Array(4);
    for (i = 1; i <= 4; i++){
       global.chVArray[i] = false;
    // Somewhere else...
    for (i = 1; i <= 4; i++){
       xfa.host.messageBox (global.chVArray[i].toString());
    BR,
    /Per

  • Array as Instance Variable

    Friends,
    Hope you can get me on the right track with this. I have an array (that must be an instance variable of type double) :
    private double[] myArray;
    that stores two values at each index:
    double length
    char unitOfMeasure
    We have to develop a method which will perform a different calculation on the value based on the identity of the unitOfMeasure.
    The method I'm working on looks like this:
    public double getDistance (int index)
    if (myArray[index].unitOfMeasure == 'a')
    return ....
    else .....
    The problem is that I get an error that reads "double cannot be dereferenced" I guess this is b/c you can't make a call with a primitive.
    How then, do I get the value of the unitOfMeasure at a particular index (as opposed to the value of length at that same index)?
    thanks!

    Thanks, I understand - much easier to do this way.Above all it's possible. You can never store more
    than one value at an array index position. At least
    not at the same time -:)private static int VALUE_INDEX = 0;
    private static int UNIT_OF_MEASURE_INDEX = 1;
    private double[][] doubles;
    doubles = new double[42][2];

  • How to read contents of an array into a variable?

    Gurus,
    I'm trying to read contents of a table or array into a varray variable. I want to know the syntax of how to accomplish the same. Please help
    Here is what i have,
    v_sub_query varray(10) of varchar2;
    v_sub_query should read contents of an array and hold values. I'm trying to do this and then use each values of v_sub_query(index) into a dynamic sql statement.
    thanks
    SS

    Sign is definately not king when it comes to PL/SQL as his advice is flawed. Row-by-row processing simply causes a lot of context switches from the PL/SQL engine to the SQL engine and back. And this results in a significant performance impact. Never mind that this style of 80's COBOL processing it sadly outdated in the 21st century when dealing with a modern RDBMS likle Oracle.
    The correct way to populate an array in PL/SQL with SQL data, is to bulk collect it. However, a varray data type is not the best suited data type for this - as they are fixed sized. Dynamic arrays are more flexible.
    Simple example:SQL> declare
      2    type TStrings is table of varchar2(30);
      3    cursor c is select object_name from all_objects order by 1;
      4    v_NameTable      TStrings;
      5  begin
      6    open c;
      7    loop
      8      fetch c bulk collect into v_NameTable limit 100;  -- fetch 100 rows at a time
      9      -- process the array
    10      for i in 1..v_NameTable.Count
    11      loop
    12          -- process element v_NameTable(i)
    13          null;
    14      end loop;
    15      exit when c%NOTFOUND;
    16    end loop;
    17    close c;
    18* end;
    SQL> /Refer to the Chapter 5. Using PL/SQL Collections and Records of the Oracle® Database PL/SQL User's Guide and Reference guide.
    As for dynamic SQL - remember to use bind variables. Do not hardcode the array values into the SQL statement as the resulting SQL will not be sharable and will cause performance problems with SQL parsing and shared pool memory fragmentation and malloc errors.

  • Splitting a string into separate values, but the array length is variable

    We are a cabinet manufacturer.  I'm trying to write a report to show the location of individual hinges on a door.  I have a string that will look something like these examples:
    60, 540
    60, 540, 956
    60, 540, 956, 1340
    It may have 2, 3, 4, or 5 locations.  (Don't think I've ever seen one over 5).
    So I have a formula that says:
    Split({Doors.HingeCenterLines},',')[1]
    This will return 60 - the first figure in my string.
    I need to have all of them separated, but the critical thing is the last measurement.  I need it to be the height of the door minus the last hinge location.  So for an example, if I have a 1400mm tall door, the 4th example string listed above would be generated.  I want my entries to look like this:
    60
    540
    956
    60
    My string always references the hinge relationship to the bottom of the door, but for the top hinge only, I need it to be based on the distance from the top of the door.
    Can anyone help with this?  Thanks in advance!

    Try this code please:
    whileprintingrecords;
    local stringvar array arr := Split({Doors.HingeCenterLines},',');
    local numbervar temp;
    local stringvar fin_string;
    local numbervar i;
    For i := 1 to ubound(arr) do
         If i = ubound(arr) then
              temp := {Door_height} - tonumber(arr[i]);
              fin_string := fin_string + totext(temp,0,"");
         else
              fin_string := fin_string + arr[i] + chr(13);
    fin_string;
    You can then right-click the field > Format Field > Common tab > Check the 'Can Grow' option.
    -Abhilash

  • Array loop - assigning variables

    Hi All,
    This is similar to a question I previously had, (which kglad so kindly helped me with) so please bare with me.
    Here is the code:
    nor = Array(a, b, c);
    aVar = Array();
    aVar[0] = 0;
    aVar[1] = 0;
    aVar[2] = 0;
    for (i=0; i<nor.length; i++)
    nor[i].onRelease = function() {
        nor[i].ivar=i;
            aVar[this.ivar] = 1;
            trace(aVar[this.ivar]);  // this outputs "1" //
                for (i=0; i<nor.length; i++)
                    trace(aVar[i]);  // this outputs "0, 0, 0" //
    The problem is that when tracing the "aVar" array, one of them should be "1" (so I think)
    Any Ideas?
    Thank you

    ahhhh... of course.
    Thanks kglad. I really appreciate your help.
    *I did revise the code slightly for future/others use.
    nor = Array(a, b, c);
    aVar = Array();
    aVar[0] = 0;
    aVar[1] = 0;
    aVar[2] = 0;
    for (i=0; i<nor.length; i++)
      nor[i].ivar=i;
    for (i=0; i<nor.length; i++)
    nor[i].onRelease = function() {
            aVar[this.ivar] = 1;
            trace(aVar[this.ivar]);  // this outputs "1" //
                for (i=0; i<nor.length; i++)
                    trace(aVar[i]);  // this outputs "0, 0, 0" //

  • Difference b/w class & instace variable

    can any one plz tell me the difference b/w class variable & instance variable.

    what about googling for "java class instance" ?

Maybe you are looking for

  • Block some A/P documents

    Hello my friends, Since Business One HR module isn't very strong, we've thought of a different solution for paying our employees. We have a Business Partner called Paycheck. Every month we create and A/P Invoice for this BP, with the total of the pay

  • "can't find remote speaker"

    AirPort works fine for an hour or two, but then the audio dies and iTunes says (something like) "can't find remote speaker". I have to disconnect from the network and connect again. "repairing wireless connection" also works. Do you know of any way a

  • User Exit/BADI for RFFOEDI1

    Hi SAP Experts, I have a requirement to add the addtional information in the output file  of the  program RFFOEDI1. Can any one help me on this? I need to know which BADI/User Exit can be used? thanks, arsgh

  • Printer not recognizing ANY paper in tray 3

    Have installed the optional tray 3 onto my printer. Have changed the paper size in trays 2 and 3 on both the printer and on my pc. No matter the size of paper, how much paper, or how I choose to print it (force to tray 3) it ALWAYS says to load paper

  • AP lost connectivity to WLC

    My understanding was that an LAP that has lost connectivity to its WLC should continue to work... At least as long as it is not rebooted. I have had a situation where a WLC went down and we lost wireless connectiviy completely. Can anyone shed shome