Float and long keywords (data type declaration)

if we have to explicitly use L or f at the end of a number, while declaring a long or float number resepectively then what is the use of “long” and “float” keywords while declaring data type of variable?

Hello Srishti
I think you are getting it wrong here f and L are the variable name like Float f = 2.5.
and now if we want to convert it into int we will use a = (int)f. I hope now you will understand that float and Long are the data types and used to define the variable of that types.

If you still have any doubt Let me Know.

for eg:- float a = 2.6f and long b = 65437L
here we have to write f and L with the literal to explicitly convert the default int or double to long and float .
but if we have to write it with the literal then what is the use of declaring float or long as data type with the variable name.

Hi Srishti
It is not necessary that you should write this only it was just to tell you that it is also a method to convert the values. So that if in future if a statement like these come you know what does it mean. These are some tricky questions which interviewer might ask you.
I hope you understand now if you understand please give me a Star/Feedback.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.