Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By anya

Thread: 2d arrays

  1. #1
    anya is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Unhappy 2d arrays

    hi every1

    i m trying to create an empty rectangle with 2d-arrays,i cannot use swing gui,just 2-d arrays to create shapes.
    plz help me out.
    private String loc[][]=new String[rows][columns];

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: 2d arrays

    That looks ok, provided rows and columns are int fields.

    A 2D array is an array of arrays; it's not a rectangle nor a shape. What are you really trying to do?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    anya is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: 2d arrays

    well i m trying to create a window which contains shapes.now the shapes and window have co-ordinates.so in order to draw the window i m drawing a 2-d array which will act like an empty rectangle window with a border of "*".

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: 2d arrays

    By 'window' I'm assuming you mean a bunch of characters displayed by your program in a command prompt window.

    You don't 'draw' an array, 2D or otherwise. You initialize it and assign values to its elements. You can print those elements to stdout using appropriate methods of Sysem.out.

    Write down the characters that form your 'window' on paper. Then write code to assign those characters to the elements of a 2D array of String or char. Once you have that down, write code to print the contents of the array to stdout.

    Compile every time you add a few lines, and get rid of any compiler errors before writing more code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    anya is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: 2d arrays

    window is the name .its an empty rectangle window which contains shapes.the rest of ur part i get it but i m not getting the correct loops.one thing i m confused is
    loc[i][j]="*" and loc[i][j]=" ".imagine a board with empty grids containing stars only at borders.i can't figure out the loops to create this.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: 2d arrays

    Did you make a start on working this out on paper?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    anya is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: 2d arrays

    Quote Originally Posted by DarrylBurke View Post
    Did you make a start on working this out on paper?

    db
    yes i have started work
    DarrylBurke likes this.

Similar Threads

  1. Copying Single Arrays to 2-D Arrays
    By jmscarlet9 in forum New To Java
    Replies: 7
    Last Post: 04-02-2012, 11:17 PM
  2. Casting Enum Type arrays to object type arrays
    By nmvictor in forum Advanced Java
    Replies: 4
    Last Post: 02-17-2012, 12:49 PM
  3. arrays and multidimensional arrays
    By belfast09 in forum New To Java
    Replies: 5
    Last Post: 06-14-2011, 01:28 PM
  4. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM
  5. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM

Posting Permissions

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