I need code for 3 dimensional array . The following code throws ArrayIndexOutofBounds Exception.
change return type as integer array not string array. I am new to array concepts.need to print 3 rows and 3 columns
String info[][][] = new String[3][4][5];
for (i=0; i<info.length ; i++)
{
for (j=0 ; j<=3; j++)
{
for(k=0;k<=info[k].length;k++)
{
info[i][j][k] = "String[" + i + "," + j + "," + k + "]";
}
}
}
System.out.println(info[i][j][k]);
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35220
7
posted
0
I think "info[k].length" should read "info[i].length" instead.
From the following code , i need to print all 3 s like 3 3 3
3 3 3
3 3 3
int[][] a2 = new int[3][3];
for (i=0; i<a2.length; i++)
{
for (j=0; j<a2[i].length; j++)
{
a2[i][j]=i;
System.out.print(" " + a2[i][j]);
Sean Clark wrote:He was so close, so I apologise if anyone thinks I am giving out the answer.
There's no ambiguity, you gave out the answer. Consider next time dropping a hint, like "what's the highest allowable index for an array of size n" or something similar--the more thought process involved the more retention, and understanding, there is. When the answer is given out, there's less thought involved, even though the solution is the same.