Skip to main content
gamedev.net
🔒 Locked

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

Started by CyberGeek Nov 10, 2004 at 2:02 PM 1 replies 2.6k views
Original Post
CyberGeek
CyberGeek
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
CyberGeek
MadLep
MadLep
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]);		}	}}
"I pretend to work, they pretend to pay me."
CyberGeek
CyberGeek
Thank you so much for your help MadLep! It works perfectly!
CyberGeek

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.