wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Two and Three dimensional array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Two and Three dimensional array " Watch "Two and Three dimensional array " New topic
Author

Two and Three dimensional array

Ravi Ahuja
Ranch Hand

Joined: Nov 13, 2006
Posts: 45


[x]
consider the following code can anyone explain me wat exactly is this code upto:?...thanks in advance
[/x]


[quoute]
public class Qaa75 {
public static void main(String[] args) {
String[][][] arr = {
{ {}, null },{ { "1", "2" },{ "1", null, "3" } } ,{}{{ "1",null } }
};
System.out.println(arr.length + arr[1][2].length);
}
}

[/quoute]
[ans]
The above code when compiled gives an array index out of bound exception can anyone explain as in how it works....
and please give me a simple example of something else is well other then this code
Thanks[/ans]


Impossible is Nothing<br />SCJP 1.4: 96%
Saurabh Vyas
Ranch Hand

Joined: Sep 02, 2003
Posts: 72
Following are the examples of 3D array :


regards
Saurabh
Amresh Singh
Greenhorn

Joined: Nov 12, 2006
Posts: 8
Hi,
The code that you have posted has compilation error at the third 2-D array...
I modified the code which looks like this.

public static void main(String[] args) {
String[][][] arr =
{
{ {}, null },
{ { "1", "2" },{ "1", null, "3" } } ,
{{},{ "1",null } }
};


System.out.println(arr.length + arr[1][2].length);
}

in the expression arr[1][2].length we are trying to access 3rd one dimensional array from second 2-D array. But the length of second 2-D array is 2. That's why AyyayIndexOutOfBoundException.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two and Three dimensional array