Arrays in Java : Please can anu one explain the output
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 !!
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
-
Varsha0802The 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. -
king99Hi Varsha Thanks for reply , Please is it possible for you to give line wise explanation , It would be helpful !!
-
Manish GoyalIt 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
You are reading an archived discussion.
Related Posts
Hi techies ,
Does any one know with confidence the name of website which provides free web hosting either for limited period or for definite time absolutely free , Please...
JK Lasers, a subsidiary of GSI Group and a leading supplier of fiber and Nd:YAG laser solutions has announced the appointment of Dr Mark Greenwood as its new General Manager....
Wireless Technology to Control and Monitor Anything from Anywhere
October 1:
Experimental Observations Confirm Einstein’s General Theory of Relativity - CrazyEngineers
MIT Artificial Leaf: Solar Cell Splits Water In H2 & O2 - CrazyEngineers
October 3:
Ubuntu 11.10 (Oneiric...
I just want to say hello to my fellow engineers.