Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By Junky
  • 1 Post By JosAH

Thread: processing a 3 dimensional array

  1. #1
    heycoa is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default processing a 3 dimensional array

    how would you process a 3 dimensional array in java? Example please?

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

    Default

    Quote Originally Posted by heycoa View Post
    how would you process a 3 dimensional array in java? Example please?
    It seems to me that you are asking a very vague and overly-general question, perhaps too vague to be answerable. You may wish to give more details and ask a more specific question. What exactly are you having problems with? What do you mean by "process"? Array of what? Also we prefer to work with your examples/attempts. A good rule of thumb is to try to put as much effort into asking your question as you'd want someone to put in trying to answer it.

    Much luck.
    Last edited by Fubarable; 07-28-2011 at 05:59 AM.

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

    Default

    The best thing to do is write a program which sums up a 3 dimensional array of integers. How would you process a single dimension array? How about a 2 dimensional array? Is there anything similar?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Quote Originally Posted by heycoa View Post
    how would you process a 3 dimensional array
    I wouldn't. I avoid 2D arrays as much as possible. There is no way I would touch a 3D array. Think redesign.
    sunde887 likes this.

  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

    I agree entirely with what junky said. I try to always avoid 2d arrays, they should only be used if you cannot think of any other way(IMO), 3d arrays would quickly get too complex to comfortably manage any serious tasks.

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

    Default

    OK, I'm curious -- why avoid multi-dimensional arrays, especially in places where they well model the problem domain? For instance, if you are creating a model for Conway's Game of Life, wouldn't you do this using a 2-dimensional array of game-cell? A sudoku grid or tic-tac-toe grid are other examples that come to mind. I've also had good success using 2-D arrays of Strings to represent the texts held by calculator buttons... e.g.,

    Java Code:
    public class MyCalc {
       //...
       private static final String[][] CALC_STRINGS = {
          {"7", "8", "9", "+"}, 
          {"4", "5", "6", "-"},
          {"1", "2", "3", "+"}, 
          {"0", ".", "/", "="}};
       //...
    
       public MyCalc() {
          //...
          btnPanel.setLayout(new GridLayout(0, CALC_STRINGS[0].length, 2, 2));
          for (int i = 0; i < CALC_STRINGS.length; i++) {
             for (int j = 0; j < CALC_STRINGS[i].length; j++) {
                JButton btn = new JButton(CALC_STRINGS[i][j]);
                if ("1234567890.".contains(CALC_STRINGS[i][j])) {
                   btn.addActionListener(new NumberButtonAction());
                } else {
                   btn.addActionListener(new OperationButtonAction());
                }
                //...
                btnPanel.add(btn);
             }
          }
          //...
    Since the array mirrors the physical reality, it makes it much easier to debug or modify.

    I'm sort of sorry for veering off the original intent of the original post, but the original poster seems to have lost interest in this thread as he has not yet replied to a single request for clarification of his problem.
    Last edited by Fubarable; 07-28-2011 at 07:00 AM.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    avoid as much as possible != will not use ;)

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

    Default

    I'm not saying there is never a need for two dimensional arrays, but perhaps the fact that I'm still not amazingly experienced leads me to avoid them if possible. Your snippet does make sense, but it could be equally represented by a single dimension array, couldn't it?

    Can you think of any great uses of 3d arrays? I feel like they would mostly just be used as exercises to help someone understand in depth how multi dimensional arrays work.

    Sudoku solvers, and conways game of life are topics I'm unfamiliar with(been meaning to read jos's post on sudoku solvers but haven't gotten to it yet), and I won't dispute that 2 d arrays are invaluable in those situations.
    Last edited by sunde887; 07-28-2011 at 07:13 AM.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    OK, I'm curious -- why avoid multi-dimensional arrays, especially in places where they well model the problem domain? For instance, if you are creating a model for Conway's Game of Life
    Conway's GOL is much better off by not using two dimensional arrays but use lists of living cells instead. That way you only have to process the 'interesting' cells. 2D arrays are so Fortranesque ;-)

    kind regards,

    Jos
    Fubarable likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help with Two Dimensional Array
    By johnjacob in forum New To Java
    Replies: 2
    Last Post: 06-03-2011, 08:22 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
  •