Array init

I am getting lot compilation errors while compiling the program below

publicclass LoadData

{

publicstaticvoid main(String args[])

{

float invt[][];

float []prct, grts[];

float [][] sms , hms[];

hms =newfloat[2][5];//Getting Compilation error on this line

}

}

I'm specifically interested to know why the line "hms = new float[2][5];" fails in compilation.

Can anybody please explain this to me?

Thanks

Kiran

[975 byte] By [kiransonajea] at [2007-11-27 2:36:25]
# 1

Because hms is a three dimensional array.

This is what happens:

float[][]sms,hms[];

//^ ^ ^

//| | |

//| | +-- 'hms' is now a 1d array of 2d arrays (== 3d array!)

//| |

//| +-- 'sms' is now a 2d array

//|

//+-- declare some 2d arrays

So you need to instantiate hms like this:

hms = new float[2][][];

// or

hms = new float[2][2][];

// or

hms = new float[2][2][2];

prometheuzza at 2007-7-12 2:55:42 > top of Java-index,Java Essentials,Java Programming...
# 2
Edited cos I was really wrong! Again...null
SeanJ@a at 2007-7-12 2:55:43 > top of Java-index,Java Essentials,Java Programming...
# 3
> ...> Edit: See... Missed that 3-Dimenional bit... Was> anything I said right though?Only that with primitives you don't need the new word. But an array of primitives are not primitives themselves, they're Objects.
prometheuzza at 2007-7-12 2:55:43 > top of Java-index,Java Essentials,Java Programming...
# 4
I didn't want to confuse the issue with my wrongness, so I edited my message. But at least I was partly right...Thanks.
SeanJ@a at 2007-7-12 2:55:43 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks a lot-kiran
kiransonajea at 2007-7-12 2:55:43 > top of Java-index,Java Essentials,Java Programming...