Glenn said:
This is to all the posters.
Thanks for the info and references.
I kept playing around and found that using double instead of float
"fixed" the problem. So my next question was going to be, "What does
the type "float" actually define?", but most of that is all resolved
now.
You didn't really fix it, you just used another variable type, that happens
to be more precise, and is the default floating point type in Java, so you
don't have to append F to explicitly tell you want a float.
The book I am using did not show an example of the "F" appended to a
number.
I don't find it to be intuitive either. If the number has a decimal
point in it, I don't think you should also need to append an "F" to
it. It is not something I would have thought of trying.
How would you choose between double and float? They both can have a floating
point in them, and you could define any of them without a floating point at
all, eg. double d = 3;
Many things in a language can't be done by just trying, or by being
intuitive, you just have have to know it. In this case, knowing the
different datatypes and how to use them, is one of the basics of learning a
language. It is a shame if this isn't in your book though.
And no, I didn't think that Java did not handle floating point
numbers. I did wonder if there was something wrong with my
installation. I looked for answers and for examples of usage, but at
the time I was not finding anything.
At this point, I am assuming that type double will hold a larger FP
number than float will. It doesn't make much sense otherwise to have
a float type. I will check that out later. So you don't have to
comment, but it's fine if you do.
Indeed, a float is 32 bits, and a double 64 bits. But you shouldn't just
start using doubles to avoid typing the F, they'll use more memory and or
slower on 32 bits machines.
Actually I wouldn't mind an answer to this question at all...
Which book to you like as a reference manual, that lists all the
classes to the core language and defines all the methods?
Don't use a book for API overviews, use
http://java.sun.com/j2se/1.4.2/docs/api/index.html
You can also download it if you're not always online.
You can also use an IDE that shows the methods and their javadoc inline,
which is very nice to quickly see what you can do with an object.