• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two and Three dimensional array

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


[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]
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following are the examples of 3D array :


regards
Saurabh
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic