Michael Migs wrote:A double is declared as "double x = 1.21;". But it would not compile without "f" suffixe. Correction should be "double x = 1.21f;".
Is that right?
Sorry you are incorrect on this point.
Any time you declare a number as double an implicit d is added to the end. So
And this compiles and run fine.
If you wanted to use a float, which is smaller then a double you need to add in the f
Here is a sample that you can try out
Please provide the book tile and authors when talking about a book as there are many different books out there, thanks.
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
posted 2 years ago
Thank you for the quick and detailed answer. Sorry about the lack of details on the book. I guess you've found it but just so that it is clear for everyone, the book is "OCA Oracle Certified Associate Java SE 8 Programmer 1" by Jeanne Boyarsky and Scott Selikoff.
Indeed I had missed the part saying that floating-point literals are assumed to be double by default unless suffixed with "f". It makes perfect sense now and I'm glad you made that clear because I would have probably missed that for the exam