I've seen some of this symbols, but I cannot find anything strange with it,
double d = 5D; float f = 3.0F;
What does the D and F behind 5 exactly means?
They're format specifiers for float and double literals. When you write 1.0 , it's ambiguous as to whether you intend the literal to be a float or double. By writing 1.0f , you're telling Java that you intend the literal to be a float, while using 1.0d specifies that it should be a double.
The "F" indicates that the literal numeric value it is appended to is a float value.
f = float. In c a value of 1 is an integer and 1.0 is a double, you use f after a decimal number to indicate that the compiler should treat it as a single precision floating point number. e.g.: If you have a line.
The %d specifies that the single variable is a decimal integer. The %n is a platform-independent newline character.
Means that these numbers are doubles and floats, respectively. Assume you have
void foo(int x); void foo(float x); void foo(double x);
and then you call
foo(5)
the compiler might be stumped. That's why you can say 5
, 5f
, or 5.0
to specify the type.
D stands for double
F for float
you can read up on the basic primitive types of java here
http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
I would like to point out that writing
5.1D or 5.1 : if you don't specify a type letter for a comma number then by default it is double
5 : without the period, by default it is an int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With