• 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

cant understand arrays

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assume the code,


int a[][]=new [2][]; // no error compiles successfully;


What dimension I am putting and in what conditions it will run successfully. Please help me


Thanks
[ July 22, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Venkattesh B", please check your private messages for an important administrative matter.
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seems like you have learned C/C++ language & you are thinking in those terms.
in java if you were to declare
int [][][] arr = new int[2][][];
it will run properly as it requires atleast one, that is the highest dimension of the array to be created.
the rest you can leave it blank. you can assign as and when you require
arr[0] = new int[3][];
arr[1] = new int [5][4];

the arrays need have all its dimensions the same length!!
arr[0].length is 3
arr[1].length is 5
arr.length is 2
 
reply
    Bookmark Topic Watch Topic
  • New Topic