HELP: UNABLE TO CREATE AND PRINT A 3-DIMENSIONAL ARRAY
//I created this program which creates 3-dimensional array and prints elements of the array
Code Java:
public class ThreeDimensionalArray
{
public static void main(String[] args)
{
int[][][] myArray;
myArray = { { {11,12,13,14},
{15,16},
{17},
{18,19}
},
{ {21,22},
{23,24,25},
{26,27,28,29}
}; // end of 3-D array
//a loop to print the values of a three-dimensional array
for(int i=0; i<myArray.length; i++)
for(int j=0; j<myArray[i].length; j++)
for(int k=0;k<myArray[j]).length;k++)
System.out.print(myArray[i][j][k]);
} //ends main
} // ends class ThreeDimensionalArray
But the program gives me this error when compiling it:
E:\JAVA_STUNTS\Array_Work>javac ThreeDimensionalArray.java
ThreeDimensionalArray.java:11: illegal start of expression
myArray = { { {11,12,13,14},
^
ThreeDimensionalArray.java:11: not a statement
myArray = { { {11,12,13,14},
^
ThreeDimensionalArray.java:11: ';' expected
myArray = { { {11,12,13,14},
^
ThreeDimensionalArray.java:11: illegal start of expression
myArray = { { {11,12,13,14},
^
ThreeDimensionalArray.java:12: not a statement
{15,16},
^
ThreeDimensionalArray.java:12: ';' expected
{15,16},
^
Please, can any one help me figure out the error??
Re: HELP: UNABLE TO CREATE AND PRINT A 3-DIMENSIONAL ARRAY
Put the definition and the assignment in one statement.
nt[][][] myArray = new int[][][] { { {11,12, ...
Otherwise move the assignment part into a constructor or method.
Re: HELP: UNABLE TO CREATE AND PRINT A 3-DIMENSIONAL ARRAY
...thanks alot,,,i solved one part of the problem,,,the only remaining exception that is thrown is an ArrayIndexOutOfBounds , in the last for loop!!!
Re: HELP: UNABLE TO CREATE AND PRINT A 3-DIMENSIONAL ARRAY
What code controls the number of iterations in the last loop?