The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem in understanding three dimensional array

3 replies on 1 page. Most recent reply: Feb 6, 2006 6:48 AM by Madhan Kumar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Madhan Kumar

Posts: 10
Nickname: madhan
Registered: Mar, 2002

Problem in understanding three dimensional array Posted: Feb 3, 2006 1:55 PM
Reply to this message Reply
Advertisement
Hi Guys,
I have a problem in understanding how three dimensinal arrays are storing in a matrix format.I have written the below coding.

class Test_exam {
 
  public static void main (String args[]) {
  
    int[][][] M;
    M = new int[4][5][3];
  
    for (int row=0; row < 4; row++) {
      for (int col=0; col < 5; col++) {
        for (int ver=0; ver < 3; ver++) {
          M[row][col][ver] = row+col+ver;
          System.out.println(M[row][col][ver]+" ");
        }
        System.out.println();
      }
      System.out.println();
    }
    
  }
  
}


But it is not displaying the answer in a matrix format.Would you please help me?

Thanks.


Dave Hinton

Posts: 42
Nickname: catbells
Registered: Oct, 2003

Re: Problem in understanding three dimensional array Posted: Feb 4, 2006 9:56 AM
Reply to this message Reply
Please post (a) the output you see, and (b) the output you expect to see.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Problem in understanding three dimensional array Posted: Feb 6, 2006 12:18 AM
Reply to this message Reply
Don't use println, but print.
After every number post a blank space.
Use println or print("\n") whenever you want to insert a line feed.


Note:
1. Threedimensional (or twodimensional) arrays do not exist. This is only a representation of an array. So you must choose how to display them.

2. You'll encounter one problem.
Your screen is two dimensional, but your array is three-dimensional. How will you display the array? You have to cut it into n two dimensional arrays and display each one of them.

Madhan Kumar

Posts: 10
Nickname: madhan
Registered: Mar, 2002

Re: Problem in understanding three dimensional array Posted: Feb 6, 2006 6:48 AM
Reply to this message Reply
Hi Guys,
I wanted to display m[3][3][3] array.The Output like

0 1 2 1 2 3 2 3 4
1 2 3 2 3 4 3 4 5
2 3 4 3 4 5 4 5 6

and i figured out my problem.
Thanks Guys.

Flat View: This topic has 3 replies on 1 page
Topic: Java beginner Previous Topic   Next Topic Topic: Program This One using NEXT LOOP

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use