Results 1 to 4 of 4
  1. #1
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default mutli dimensional array

    Hi there,
    Is there any way we can allocate value on mutlidemensional array dynamically?

    I mean this my multi-dimenstional array

    int[][]linegraphX = {{0,70,70,140,140,210,210,280,280,350,350,420,420, 490,490,560,560,630,630,700,700}};

    but all those values such as 0,70,70,140,140.....700,700 are entered manually by me.

    can we assign value dynamically/not manually?

    Thank you

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Yes, you can.

  3. #3
    ccie007 is offline Senior Member
    Join Date
    May 2010
    Posts
    112
    Rep Power
    0

    Default

    How can i do that?

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You can use a loop which uses the value of i to set each spot in the loop. For instance you could do
    Java Code:
    for(int i = 0; i < array.length; i++){
      array[i] = i * 123;
    }
    You can also use random for randomly generated items and more.

Similar Threads

  1. 2 dimensional array
    By sehudson in forum New To Java
    Replies: 5
    Last Post: 02-20-2011, 11:56 PM
  2. 2 dimensional array help!
    By ber1023 in forum New To Java
    Replies: 9
    Last Post: 01-02-2011, 12:29 AM
  3. Two dimensional array
    By niu_niu in forum New To Java
    Replies: 4
    Last Post: 06-13-2010, 12:34 AM
  4. about two dimensional array
    By matin1234 in forum New To Java
    Replies: 2
    Last Post: 06-01-2010, 11:09 AM
  5. two-dimensional array
    By kHim in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 07:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •