aspose file tools*
The moose likes Java in General and the fly likes Trouble with compiling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Trouble with compiling?" Watch "Trouble with compiling?" New topic
Author

Trouble with compiling?

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050



I am not getting the logic why is it the number 7 not being assigned to the 0 index?


http://www.lifesbizzare.blogspot.com || OCJP:81%
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
books[0] is declared to hold an int or an int array?
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050

John Jai wrote:books[0] is declared to hold an int or an int array?


I am assigning a numerical value to an index 0 , isnt it right?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
books is a multidimensional array that holds integer arrays. So book[0] - is a place holder for an integer array. book[1] for another and book[2] another. The no. of integer arrays that book can hold is declared with the size 3.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050

Ok, so what does the 2 empty square bracket specify in this scenario?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3056
    
  33

Vishal Hegde wrote:Ok, so what does the 2 empty square bracket specify in this scenario?

Indicates that books is an array of arrays (multidimensional array)
so books[0], books[1], books[2] would be 3 arrays each of whose length can be anything (as you havent mentioned the 2nd dimension value in the declaration. Do try out a full fledged program and see how it behaves.


Mohamed Sanaulla | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
John Jai wrote: . . . multidimensional array . . .
Careful; the newbies will believe there actually is such a thing as a multidimensional array!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vishal Hegde wrote:

I am not getting the logic why is it the number 7 not being assigned to the 0 index?


Because anumber is not the same as aNumber. But I'm guessing that's not really the problem. This is why you should copy/paste code, not type it fresh here.

Assuming you have the correct variable name so that you're not getting a symbol not found error, you're instead getting this error message. Read it closely. What do you think it means?




You know that X[] arr; means that each element of arr is an X, right? Well, if you have int[][] arr;, then what is X here? And therefore what type is each element of arr?
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050

Jeff Verdegan wrote:
Vishal Hegde wrote:

I am not getting the logic why is it the number 7 not being assigned to the 0 index?


Because anumber is not the same as aNumber. But I'm guessing that's not really the problem. This is why you should copy/paste code, not type it fresh here.

Assuming you have the correct variable name so that you're not getting a symbol not found error, you're instead getting this error message. Read it closely. What do you think it means?




You know that X[] arr; means that each element of arr is an X, right? Well, if you have int[][] arr;, then what is X here? And therefore what type is each element of arr?


Hi Jeff,

int[][] in here x is an int array and the type of element will be having an int array :O

ok if incase there are two [][] then it means it takes int array, but what if there are three square brackets [][][] what in that case ??
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Vishal Hegde wrote:ok if incase there are two [][] then it means it takes int array, but what if there are three square brackets [][][] what in that case ??

Then it's an array of array of arrays. If you declare numbers as an int[][][], then numbers[0] is an array-of-arrays-of-ints, numbers[0][0] is an array-of-ints, and numbers[0][0][0] is an int.

The thing to remember is that arrays are just objects. You can have an array of any object you want, including other arrays. And arrays of those, and of those, etc. There's no absolute restriction on how many levels you can nest it as, but as you can imagine it gets difficult to follow so it's not a good idea to take it too far.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Vishal Hegde wrote:ok if incase there are two [][] then it means it takes int array, but what if there are three square brackets [][][] what in that case ??

myarray[x] = <array of int arrays>
myarray[x][y] = <array of ints>
myarray[x][y][z] = <int>


Joanne
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050

Hi , thanks a lot My doubts are getting cleared now
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Matthew Brown wrote: . . . There's no absolute restriction on how many levels you can nest it as, . . .
[Pantomime mode]Oh, yes, there is![/Pantomime mode]
JVM Specification §4.10.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Campbell Ritchie wrote:
Matthew Brown wrote: . . . There's no absolute restriction on how many levels you can nest it as, . . .
[Pantomime mode]Oh, yes, there is![/Pantomime mode]
JVM Specification §4.10.


The number of dimensions in an array is limited to 255

So if it had, say, 3 dimensions, wouldn't that make it a multidimensional array




Edit: Note to newbies. I'm just winding Campbell up here. He is right when he says (over and over again) that there is no such thing as a multidimensional array in Java
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
It means they are using language loosely, since it says elsewhere that a mmmmm-[I can’t say it]-dimensional array is an array of arrays.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with compiling?
 
Similar Threads
K&B, Chapter 3: Assignments, page 224
Compiler error or class cast exception
Searching an Array
Dynamic dispatch
array question and confusion