Because you cannot assign a double value to a float .
The reason is here 2.0 is double , by default the precision is double ,
Here is an example we write float x = 3.2f and not float x = 3.2 , f indicates that value is float
If we write float x = 3.2 , here by default 3.2 is double .
Hence the problem
you can type cast it float = (float)(5/2.0) ;
And then assign it .
I hope this clears it.
And WELCOME to javaranch.
Understanding is Everything - Peter Lord
Joined: Nov 15, 2010
My question is answered.
Experienced Java programmers always used to refer to coderanch. Now I can see why.
This was the fastest resolution I ever got on any forum.