CrazyEngineers
  • Hi techies ,

    I am new to java and trying to understand arrays but was stuck in concepts , Please any one can explain the following is the code :

    class ThreeDMatrix
    {

    public static void main(String args[])
    {
    int threeD[][][] = new int[3][4][5];
    int i, j, k;
    for(i=0; i<3; i++)
    for(j=0; j<4; j++)
    for(k=0; k<5; k++)
    threeD[j][k] = i * j * k;
    for(i=0; i<3; i++)
    {
    for(j=0; j<4; j++)
    {
    for(k=0; k<5; k++)
    System.out.print(threeD[j][k] + " ");
    System.out.println();
    }
    System.out.println();
    }
    }
    }

    Output of this program is :

    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0

    I would be thankful for the help ,Regards King99 !!
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Varsha0802

    MemberOct 12, 2011

    The program's full output is:

    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0
    0 0 0 0 0

    0 0 0 0 0
    0 1 2 3 4
    0 2 4 6 8
    0 3 6 9 12

    0 0 0 0 0
    0 2 4 6 8
    0 4 8 12 16
    0 6 12 18 24

    The output is self explanatory, As the array indexes start by 0, the first matrix contain all zeros because i's value will be zero for it.
    Are you sure? This action cannot be undone.
    Cancel
  • king99

    MemberOct 12, 2011

    Hi Varsha Thanks for reply , Please is it possible for you to give line wise explanation , It would be helpful !!
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberOct 12, 2011

    It means 3 blocks , 4 rows and 5 columns.

    For 1 block, it will create 4 rows and for one row it will create 5 columns
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register