Results 1 to 5 of 5
  1. #1
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default assign a value to two dimensional array

    it s me mak from india.
    i want to know how to assign value in two dimensional array.


    for ex;

    int a[][]=new int[2][2];
    int a[2][2]={{0,1},{1,0}};

    but it makes error......

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    with this:
    Java Code:
    int a[][] = new int[2][2];
    this:
    Java Code:
    a[1]
    refers to a 1 dimensional array, and this
    Java Code:
    a[1][1] = 5;
    refers to an int. Note that this:
    Java Code:
    a[2][2] = 5;
    will cause an error as the array indices inside the square bracket can only be 0 or 1 since arrays start at 0 and you declared an array of 2 items.

  3. #3
    sunilpatel28 is offline Member
    Join Date
    Dec 2008
    Posts
    8
    Rep Power
    0

    Default use array by following way

    int a[][]={{0,1},{1,0}};

  4. #4
    kzaman's Avatar
    kzaman is offline Member
    Join Date
    Oct 2011
    Location
    Dhaka, Bangladesh
    Posts
    4
    Rep Power
    0

    Default Re: use array by following way

    Code spoon feeding removed.
    Last edited by sunde887; 10-05-2011 at 05:22 AM.

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

    Default Re: assign a value to two dimensional array

    Three things:
    1) don't spoon feed
    2) don't resurrect threads ~3 years old
    3) don't edit code back in after I have removed it.

    Deleting this post.

Similar Threads

  1. Array Assign Values from a Textfile
    By fawadafr in forum Java Applets
    Replies: 6
    Last Post: 11-30-2008, 12:10 AM
  2. two-dimensional array
    By kHim in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 07:21 PM
  3. Multi dimensional Array
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 03:34 PM
  4. How to initialize a two dimensional Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:48 PM
  5. Help with array multi-dimensional
    By barney in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:00 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
  •