Jump to content
  • Advertisement
Sign in to follow this  
CyberGeek

[java] Hardcoding numbers into a 3 dimensional array in Java

This topic is 5146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. I was wondering if someone could help me with a problem I am having. I am trying to create a 3 dimensional array in Java and fill it right after I create it. I have done this with 2D arrays before with a format like this:

 int array[][] = {
	{0,0,0,0,0,0},
   	{2,4,6,8,10,12},
   	{14,16,18,20,22,24},
   	{26,28,30,32,34,36},
   };


I cant figure out how to add the third dimension though. I have searched the net and tons of Java tutorials and books but they all just cover one and two dimensional arrays. I appreciate any help I can get on this matter. Thanks so much!!! Josh a.k.a. CyberGeek

Share this post


Link to post
Share on other sites
Advertisement
Pretty much the same way, just nested another level deeper.


String[][][] array3 =
{
{
{"a","b","c"},
{"d","e","f"}
},
{
{"g","h","i"},
{"j","k","l"}
}
};

for (int i=0;i<array3.length;i++)
{
for (int j=0;j<array3.length;j++)
{
for (int k=0;k<array3[j].length;k++)
{
System.out.println(array3[j][k]);
}
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!