This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes cant understand arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "cant understand arrays" Watch "cant understand arrays" New topic
Author

cant understand arrays

Venkattesh Iyer
Greenhorn

Joined: Jun 15, 2008
Posts: 6
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63052
    
  69

"Venkattesh B", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
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


SCJP 6 83%
Working on SCWCD/OCPJWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cant understand arrays
 
jQuery in Action, 3rd edition