Your variable n is just an integer primitive...it has no length property.
As a small matter of coding practice consider changing the following:
to just
No need to declare the local variable without initializing it to some value here.
I'm not sure what is giving you an error saying 'cannot be dereferenced' but for me when I popped your code into Eclipse it instantly pointed out to me that
"The primitive type int of n does not have a field length"
Alex Hurtt wrote:
I'm not sure what is giving you an error saying 'cannot be dereferenced' but for me when I popped your code into Eclipse it instantly pointed out to me that
"The primitive type int of n does not have a field length"
Alex Hurtt wrote:
I'm not sure what is giving you an error saying 'cannot be dereferenced' but for me when I popped your code into Eclipse it instantly pointed out to me that
"The primitive type int of n does not have a field length"
Try to compile from the command line.
Ok I did and I got the authors error with the code as it was written...rather wierd way for the compiler to tell me that a primitive int doesn't have a .length property. When I make the modifications I suggested to the code, it compiles fine.
Writing error messages which users can understand is the most difficult part of creating a compiler. Eclipse is much better for error messages than the Sun/Oracle compiler.
Don't get me started about those stupid light bulbs.