Check out Manning's Countdown to 2014. Use discount code crdotd14 all month for 50% off every deal.
Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login

# Multi-dimensional array

Seema Sharma
Ranch Hand

Joined: May 24, 2007
Posts: 78
Hi,

Given:
12. float f[ ][ ][ ] = new float[3][][];
13. float f0 = 1.0f;
14. float[ ][ ] farray = new float[1][1];

Which is valid?
A. f[0] = f0;
B. f[0] = farray;
C. f[0] = farray[0];
D. f[0] = farray[0][0];

Regards,
Seema
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169

B chicce is correct because f[0] refers to a 2dimensional floating array and since farray is 2dimensional so f[0] = farray.

to help you to understand better let me make a change in array f..

now:
f[0] refers to 2dimensional float array.
f[0][0] refers to a 1dimensional float array and
f[0][0][0] stores a floating point value !!

hope this explanantion helps!!
[ July 25, 2007: Message edited by: Priyam Srivastava ]

"History would be kind to me, for I intend to write it."
Seema Sharma
Ranch Hand

Joined: May 24, 2007
Posts: 78
Priyam,
Can you explain me this with small example. I still have a doubt how:

f[0] refers to 2dimensional float array.
f[0][0] refers to a 1dimensional float array and
f[0][0][0] stores a floating point value

Regards,
Seema
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169

can you tell exactly what your confusion is, as it might help you to give a better example..
thanks!
[ July 25, 2007: Message edited by: Priyam Srivastava ]
Robert Horvath
Greenhorn

Joined: Jan 03, 2007
Posts: 15
Hi Seema,

I've prepared a short example:

Cheers,
Robert
[ July 25, 2007: Message edited by: Robert Horvath ]
Seema Sharma
Ranch Hand

Joined: May 24, 2007
Posts: 78
Thanks Priyam and Robert for your explanations.

I agree. Here's the link: http://aspose.com/file-tools

subject: Multi-dimensional array